File size: 2,215 Bytes
477efd3
 
a2996e0
33036ed
 
8be9640
33036ed
8be9640
33036ed
 
8be9640
33036ed
8be9640
a2996e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477efd3
35a2c36
 
 
477efd3
 
 
 
 
 
6465cf2
8321d46
06ac9d4
6465cf2
477efd3
 
 
308c3d8
cc7bc84
8321d46
477efd3
 
8321d46
 
477efd3
 
a2996e0
477efd3
 
 
f1f3052
477efd3
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import streamlit as st
from PIL import Image
import google.generativeai as genai
from googletrans import Translator, LANGUAGES

#def translate_to_persian(text):
    # Instantiate the Translator object
translator = Translator()

    # Translate the text
#translation = translator.translate(text, src='en', dest='fa')

    #return translation.text

genai.configure(api_key="AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8")

# Set up the model
generation_config = {
  "temperature": 0.9,
  "top_p": 1,
  "top_k": 1,
  "max_output_tokens": 2048,
}

safety_settings = [
  {
    "category": "HARM_CATEGORY_HARASSMENT",
    "threshold": "BLOCK_MEDIUM_AND_ABOVE"
  },
  {
    "category": "HARM_CATEGORY_HATE_SPEECH",
    "threshold": "BLOCK_MEDIUM_AND_ABOVE"
  },
  {
    "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
    "threshold": "BLOCK_MEDIUM_AND_ABOVE"
  },
  {
    "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
    "threshold": "BLOCK_MEDIUM_AND_ABOVE"
  },
]
text_input = st.text_input('Enter some text')

model = genai.GenerativeModel(model_name="gemini-pro",
                              generation_config=generation_config,
                              safety_settings=safety_settings)

prompt_parts = [text_input]

response = model.generate_content(prompt_parts)


#to_markdown(response.text)

# Set up the title of the app
st.title('Simple Streamlit App')

# File uploader to allow users to upload images
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

mod = genai.GenerativeModel('gemini-pro-vision')

#res.resolve()

# Display the uploaded image
if uploaded_file is not None:
    image = Image.open(uploaded_file)
    res = mod.generate_content(["" + text_input, image], stream=True)
    res.resolve()
    #st.image(image, caption='Uploaded Image', use_column_width=True)

# Button to print "Hey you"
    if st.button('Hey Button'):
        st.write(res.text)

# Text input
#text_input = st.text_input('Enter some text')

# Button to print the text from input
if st.button('Print Text'):
    st.write(translator.translate(response.text, src='en', dest='fa').text)#translate_to_persian("Hello, how are you?"))#response.text))

# Run this with `streamlit run your_script.py`