import PIL.Image import gradio as gr import base64 import time import os import google.generativeai as genai # Set Google API key genai.configure(api_key = os.environ['GOOGLE_API_KEY']) # Create the Model txt_model = genai.GenerativeModel('gemini-pro') vis_model = genai.GenerativeModel('gemini-pro-vision') # Image to Base 64 Converter def image_to_base64(image_path): with open(image_path, 'rb') as img: encoded_string = base64.b64encode(img.read()) return encoded_string.decode('utf-8') # Function that takes User Inputs and displays it on ChatUI def query_message(history,txt,img): if not img: history += [(txt,None)] return history base64 = image_to_base64(img) data_url = f"data:image/jpeg;base64,{base64}" history += [(f"{txt} ![]({data_url})", None)] return history # Function that takes User Inputs, generates Response and displays on Chat UI def llm_response(history,text,img): if not img: response = txt_model.generate_content(text) history += [(None,response.text)] return history else: img = PIL.Image.open(img) response = vis_model.generate_content([text,img]) history += [(None,response.text)] return history # Interface Code with gr.Blocks() as app: # heading = gr.title("Pet Diet Plan Generator", level=1) # Add a heading # heading = gr.Markdown("# Pet Diet Plan Generator") # Subheading # subheading = gr.Markdown("### Answer the following questions to generate a personalized diet plan.") gr.HTML( """

GEMINI PRO CHATBOT

Gemini Pro isn't just a language model; it's a creative powerhouse, a code-wielding wizard , and a tireless knowledge explorer, all rolled into one. It fuels your artistic expression, supercharges your productivity, and bridges the code gap. Dive into scientific mysteries with its help, or imagine AI-powered healthcare. This ever-evolving entity, with its cutting-edge edge, redefines our relationship with technology .



Welcome to the Gemini Pro revolution! 📈

If you like our project, please give us a star on Github to stay updated with the latest developments.

Project Page



textdiffuser-2


CAPABILITIES


✅Writes in any style, from poems to scripts, sparking your imagination and breaking writer's block.Analyzes data, uncovers patterns, and proposes hypotheses.

✅Translates languages, summarizes documents, and answers questions, freeing you to focus on the big picture.Seamlessly handles text, code, and even images.

✅ Generates and translates code in different languages, speeding up development and democratizing coding.



""") # subheading = gr.Heading("Answer the following questions to generate a personalized diet plan.", level=3) # Add a subheading with gr.Row(): image_box = gr.Image(type="filepath") chatbot = gr.Chatbot( scale = 2, height=750 ) text_box = gr.Textbox( placeholder="Enter text and press enter, or upload an image to start", container=False, ) btn = gr.Button("Submit") clicked = btn.click(query_message, [chatbot,text_box,image_box], chatbot ).then(llm_response, [chatbot,text_box,image_box], chatbot ) gr.Markdown("## Prompt Examples") gr.Examples( [ ["Describe the painting in a poetic way.",'eg1.png'], [" Craft a persuasive advertisement for this electric car that highlights its innovative features and eco-friendly benefits, using language that appeals to a tech-savvy audience..",'eg2.png'], ["Count no. of people in this image.",'eg3.jpg'], ["Tell me some fact about this dog breed.",'eg4.webp'], ], [ text_box, image_box ], examples_per_page=25 ) gr.HTML( """

Disclaimer: Please note that the demo is intended for academic and research purposes ONLY. Any use of the demo for generating inappropriate content is strictly prohibited. The responsibility for any misuse or inappropriate use of the demo lies solely with the users who generated such content, and this demo shall not be held liable for any such use.

All the images and video belongs to their respective owners/organisations. I dont claim any copywrite on any image and video.Big shoutout to hugging face community.

""" ) app.queue() app.launch(auth=('user','admin'),auth_message="Enter your username and password.If you don't have it please dm me on linkedin @ https://www.linkedin.com/in/jaskiratsingh04 or Email me @singh.kirat.0409@gmail.com Thanks!",debug=True,share=True)