from dotenv import load_dotenv import streamlit as st import os import google.generativeai as genai from PIL import Image load_dotenv() GOOGLE_API_KEY = os.getenv("GOOGLE_API") genai.configure(api_key=GOOGLE_API_KEY) model = genai.GenerativeModel('gemini-pro') model_vision = genai.GenerativeModel('gemini-pro-vision') def gemini_response(question): try: response1 = model.generate_content(question) return response1.text except Exception as e: raise e def gemini_response_vision(input_texts, image): try: if input_texts != "": response2 = model_vision.generate_content([input_texts, image]) else: response2 = model_vision.generate_content(image) return response2.text except Exception as e: raise e # streamlit_analytics.start_tracking() tab1, tab2 = st.tabs(["TAB_1:Gemini LLM App Q & A:sunglasses:", "TAB_2:Gemini-Pro-Vision Image To Text:rocket:"]) with tab1: st.title('Generative Question And Answer :blue[Gemini LLM App] :sunglasses:') input_1 = st.text_input("Ask Question:") submit1 = st.button("Generate Response") if submit1: if input_1 is not None: st.write('Your Query Response') response = gemini_response(input_1) st.write(response) else: st.write("Enter The Text") with tab2: st.title('Generative Image Description :blue[Gemini-Pro-Vision LLM App] :sunglasses:') uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) input_2 = st.text_input("Text for Image: Ask question related to uploaded image") if uploaded_image is not None: img = Image.open(uploaded_image) st.image(img, caption="upload images", use_column_width=True) submit2 = st.button("Generate Text from Image ") if submit2: st.subheader("Response:") res = gemini_response_vision(input_texts=input_2, image=img) st.write(res)