File size: 1,987 Bytes
8f9e87a
 
 
 
 
 
 
41b20e0
8f9e87a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)