Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import google.generativeai as genai
|
4 |
+
from deep_translator import GoogleTranslator
|
5 |
+
|
6 |
+
genai.configure(api_key="AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8")
|
7 |
+
|
8 |
+
# Set up the model
|
9 |
+
generation_config = {
|
10 |
+
"temperature": 0.9,
|
11 |
+
"top_p": 1,
|
12 |
+
"top_k": 1,
|
13 |
+
"max_output_tokens": 2048,
|
14 |
+
}
|
15 |
+
|
16 |
+
safety_settings = [
|
17 |
+
{
|
18 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
19 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
23 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
27 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
31 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
32 |
+
},
|
33 |
+
]
|
34 |
+
|
35 |
+
text_input = st.text_input('سوالتان را در مورد علایم، داروها، عوارض و یا آزمایشات دیابت بپرسید', placeholder='من بیمار مبتلا به دیابت و سکته قلبی هستم و از متفورمین و پیوگلیتازون مصرف میکنم، این داروهارو چجوری مصرف کنم و آیا عوارضی خواهند داشت با توجه به بسکته قلبی که داشتهام؟')
|
36 |
+
|
37 |
+
model = genai.GenerativeModel(model_name="gemini-pro",
|
38 |
+
generation_config=generation_config,
|
39 |
+
safety_settings=safety_settings)
|
40 |
+
|
41 |
+
prompt_parts = [text_input]
|
42 |
+
|
43 |
+
response = model.generate_content(prompt_parts)
|
44 |
+
l=[]
|
45 |
+
l.append(response)
|
46 |
+
|
47 |
+
#to_markdown(response.text)
|
48 |
+
|
49 |
+
# Set up the title of the app
|
50 |
+
#st.title('Simple Streamlit App')
|
51 |
+
|
52 |
+
# File uploader to allow users to upload images
|
53 |
+
uploaded_file = st.file_uploader("عکس زخمتان را بفرستید", type=["jpg", "jpeg", "png"])
|
54 |
+
|
55 |
+
mod = genai.GenerativeModel('gemini-pro-vision')
|
56 |
+
|
57 |
+
#res.resolve()
|
58 |
+
|
59 |
+
# Display the uploaded image
|
60 |
+
if uploaded_file is not None:
|
61 |
+
image = Image.open(uploaded_file)
|
62 |
+
res = mod.generate_content(["" + text_input, image], stream=True)
|
63 |
+
res.resolve()
|
64 |
+
#st.image(image, caption='Uploaded Image', use_column_width=True)
|
65 |
+
|
66 |
+
# Button to print the response
|
67 |
+
if st.button('Hey Button'):
|
68 |
+
response_parts = res.candidates[0].content.parts
|
69 |
+
response_text = ""
|
70 |
+
for part in response_parts:
|
71 |
+
response_text += part.text
|
72 |
+
st.write(response_text)
|