File size: 2,363 Bytes
dc577a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6cf1426
 
dc577a1
 
 
 
 
 
 
 
 
 
 
 
 
5d432e5
dc577a1
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from PIL import Image
import google.generativeai as genai
from deep_translator import GoogleTranslator

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('سوالتان را در مورد علایم، داروها، عوارض و یا آزمایشات دیابت بپرسید', placeholder='من بیمار مبتلا به دیابت و سکته قلبی هستم و از متفورمین و پیوگلیتازون مصرف میکنم، این داروهارو چجوری مصرف کنم و آیا عوارضی خواهند داشت با توجه به بسکته قلبی که داشته‌ام؟')

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)
l=[]
l.append(response)

#to_markdown(response.text)
if st.button('Button'):
    st.write(l[0])
# 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("عکس زخمتان را بفرستید", 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 the response
    if st.button('Hey Button'):
        response_parts = res.candidates[0].content.parts
        response_text = ""
        for part in response_parts:
            response_text += part.text
        st.write(response_text)