Pezh commited on
Commit
ce9ab9b
·
verified ·
1 Parent(s): bec1177

Upload app (10).py

Browse files
Files changed (1) hide show
  1. app (10).py +143 -0
app (10).py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import requests
4
+ import google.generativeai as genai
5
+ #from googletrans import Translator, LANGUAGES
6
+ from deep_translator import GoogleTranslator
7
+
8
+ #def translate_to_persian(text):
9
+ # Instantiate the Translator object
10
+ #translator = Translator()
11
+
12
+ # Translate the text
13
+ #translation = translator.translate(text, src='en', dest='fa')
14
+
15
+ #return translation.text
16
+ st.markdown("""
17
+ <style>
18
+ input {
19
+ unicode-bidi: bidi-override;
20
+ direction: RTL;
21
+ }
22
+ label {
23
+ direction: RTL;
24
+ font-size: 54px; /* Updated font size here */
25
+ display: block;
26
+ text-align: right;
27
+ margin-top: 5px;
28
+ margin-bottom: 5px;
29
+ }
30
+ .title {
31
+ text-align: center;
32
+ font-size: 40px;
33
+ }
34
+ div.stButton > button:first-child {
35
+ background-color: #1640D6 !important;
36
+ color: white !important;
37
+ font-size: 40px !important;
38
+ height: 1em !important;
39
+ width: 3em;
40
+ border-radius: 5px;
41
+ border: none;
42
+ }
43
+ div.stButton {
44
+ text-align: center;
45
+ }
46
+
47
+ /* Media query for responsiveness to mobile devices */
48
+ @media only screen and (max-width: 600px) {
49
+ label {
50
+ font-size: 18px; /* Adjusted font size for mobile devices */
51
+ }
52
+ }
53
+ </style>
54
+ """, unsafe_allow_html=True)
55
+
56
+ st.markdown('<div class="title">Pezhma آزمایشگاه</div>', unsafe_allow_html=True)
57
+
58
+ #st.title('Medicmate.ir')
59
+
60
+ text_input = st.text_input('شرح حال بیمار را وارد کنید', placeholder='بیمار پسر 16 ساله که با شکایت زردی، اسهال و بی‌حالی مراجعه کرده است')
61
+
62
+ text_input2 = st.text_input('اگر نام آزمایش را مید‌انید، وارد نمایید', placeholder='Liver function test (or LFT)')
63
+
64
+ #سی تی اسکن شکم-لگن با کنتراست خوراکی و وریدی'
65
+
66
+ genai.configure(api_key="AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8")
67
+
68
+ uploader_key = 'file_uploader'
69
+
70
+ # Function to clear the uploaded file
71
+
72
+ #def clear_file():
73
+ #if st.session_state != None:
74
+ # del st.session_state[uploader_key] # This clears the file uploader widget
75
+
76
+ # Check if the delete button is pressed
77
+
78
+ # File uploader with the key
79
+ uploaded_file = st.file_uploader("Just Image", type=["jpg", "jpeg", "png"], key=uploader_key)
80
+
81
+ mod = genai.GenerativeModel('gemini-pro-vision')
82
+
83
+ txt = text_input + text_input2
84
+ hox = """
85
+ As a helpful AI assistant, I will interpret your blood test results as Dr. Pejman. First, I will check the provided photo to ensure it's a test photo. If it's not a test photo, I will respond with: "I am Dr. Pejman. Please send your test photo."
86
+
87
+ I can interpret various blood tests, such as liver function (LFT), lipids, hormonal, iron panel, complete blood count (CBC), urinalysis (U/A), sperm analysis, and more. When interpreting the test results, I will use the same symbol for each parameter. For example, I will use Hb for hemoglobin and Plt for platelets.
88
+
89
+ When providing interpretations, I will follow this format:
90
+
91
+ * If a value is high, I will say, "The [parameter] level is high." For example, if Hb is high, I will say, "The Hb level is high."
92
+ * If a value is low, I will say, "The [parameter] level is low." For example, if Plt is low, I will say, "The Plt level is low."
93
+ * If a value is normal, I will not provide any comments or interpretations for that parameter.
94
+
95
+ Please send me your blood test photo, and I will interpret it accordingly.
96
+ """
97
+ l=[]
98
+ g=[]
99
+ # Display the image if available
100
+ if uploaded_file is not None:
101
+ image = Image.open(uploaded_file)
102
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
103
+ trans = GoogleTranslator(source='fa', target='en')
104
+ # Translate the text to English
105
+ g.append(txt)#text_input)
106
+ trans_text = trans.translate(g[0])
107
+ res = mod.generate_content(["" + g[0], image], stream=True)
108
+ res.resolve()
109
+ l.append(res.text)
110
+ if st.button('تفسیر آزمایش'):
111
+ #st.write(res.text)
112
+ translator = GoogleTranslator(source='en', target='fa')
113
+ # Translate the text to Persian
114
+ translated_text = translator.translate(l[0])
115
+ url = 'https://pezhma.ir/save_data.php'
116
+ data = {'text_input': translated_text}
117
+ response = requests.post(url, data=data)
118
+
119
+ if response.status_code == 200:
120
+ index = response.text # Retrieve the index from the response
121
+ st.success(f'تفسیر آزمایش خود را با وارد کردن کد در باکس پایین بدست آورید: {index}')
122
+ else:
123
+ st.error('Error saving data')
124
+
125
+ # Display the translated text
126
+ #st.markdown(f"<div style='text-align: center; color: blue; font-size: 20px;'>{translated_text}</div>", unsafe_allow_html=True)
127
+
128
+ #if st.button('Delete'):
129
+ # clear_file()
130
+ #uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
131
+
132
+ #res.resolve()
133
+
134
+ # Display the uploaded image
135
+ #if uploaded_file is not None:
136
+ # image = Image.open(uploaded_file)
137
+ # res = mod.generate_content(["" + text_input, image], stream=True)
138
+ # res.resolve()
139
+ # l.append(res.text)
140
+ #st.image(image, caption='Uploaded Image', use_column_width=True)
141
+
142
+ # Button to print "Hey you"
143
+