|
import streamlit as st |
|
from PIL import Image |
|
import requests |
|
import google.generativeai as genai |
|
|
|
from deep_translator import GoogleTranslator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
input { |
|
unicode-bidi: bidi-override; |
|
direction: RTL; |
|
} |
|
label { |
|
direction: RTL; |
|
font-size: 54px; /* Updated font size here */ |
|
display: block; |
|
text-align: right; |
|
margin-top: 5px; |
|
margin-bottom: 5px; |
|
} |
|
.title { |
|
text-align: center; |
|
font-size: 40px; |
|
} |
|
div.stButton > button:first-child { |
|
background-color: #1640D6 !important; |
|
color: white !important; |
|
font-size: 40px !important; |
|
height: 1em !important; |
|
width: 3em; |
|
border-radius: 5px; |
|
border: none; |
|
} |
|
div.stButton { |
|
text-align: center; |
|
} |
|
|
|
/* Media query for responsiveness to mobile devices */ |
|
@media only screen and (max-width: 600px) { |
|
label { |
|
font-size: 18px; /* Adjusted font size for mobile devices */ |
|
} |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
st.markdown('<div class="title">Pezhma آزمایشگاه</div>', unsafe_allow_html=True) |
|
|
|
|
|
|
|
text_input = st.text_input('شرح حال بیمار را وارد کنید', placeholder='بیمار پسر 16 ساله که با شکایت زردی، اسهال و بیحالی مراجعه کرده است') |
|
|
|
text_input2 = st.text_input('اگر نام آزمایش را میدانید، وارد نمایید', placeholder='Liver function test (or LFT)') |
|
|
|
|
|
|
|
genai.configure(api_key="AIzaSyBd36RWeqDpLur3E7TTlX3wnyIh_rdhsU8") |
|
|
|
uploader_key = 'file_uploader' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uploaded_file = st.file_uploader("Just Image", type=["jpg", "jpeg", "png"], key=uploader_key) |
|
|
|
mod = genai.GenerativeModel('gemini-pro-vision') |
|
|
|
txt = text_input + text_input2 |
|
hox = """ |
|
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." |
|
|
|
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. |
|
|
|
When providing interpretations, I will follow this format: |
|
|
|
* 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." |
|
* 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." |
|
* If a value is normal, I will not provide any comments or interpretations for that parameter. |
|
|
|
Please send me your blood test photo, and I will interpret it accordingly. |
|
""" |
|
l=[] |
|
g=[] |
|
|
|
if uploaded_file is not None: |
|
image = Image.open(uploaded_file) |
|
st.image(image, caption='Uploaded Image.', use_column_width=True) |
|
trans = GoogleTranslator(source='fa', target='en') |
|
|
|
g.append(txt) |
|
trans_text = trans.translate(g[0]) |
|
res = mod.generate_content(["" + g[0], image], stream=True) |
|
res.resolve() |
|
l.append(res.text) |
|
if st.button('تفسیر آزمایش'): |
|
|
|
translator = GoogleTranslator(source='en', target='fa') |
|
|
|
translated_text = translator.translate(l[0]) |
|
url = 'https://pezhma.ir/save_data.php' |
|
data = {'text_input': translated_text} |
|
response = requests.post(url, data=data) |
|
|
|
if response.status_code == 200: |
|
index = response.text |
|
st.success(f'تفسیر آزمایش خود را با وارد کردن کد در باکس پایین بدست آورید: {index}') |
|
else: |
|
st.error('Error saving data') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|