Download app.py from Pezh/piham: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/Pezh/piham/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/piham/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/piham/resolve/main/app.py
1.89 kB
| import streamlit as st | |
| from PIL import Image | |
| import google.generativeai as genai | |
| from deep_translator import GoogleTranslator | |
| st.markdown(""" | |
| <style> | |
| /* CSS styling */ | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.markdown('<div class="title">Medicmate.ir</div>', unsafe_allow_html=True) | |
| text_input = st.text_input('شرح حال بیمار را وارد کنید', placeholder='بیمار خانم 59 ساله با سابقه GERD که با شکایت دیسفاژی و کاهش وزن مراجعه کرده است') | |
| text_input2 = st.text_input('نوع و محل نمونه وارد شود', placeholder='اکسیژن آندوسکوپی از توده نزدیک به کاریا') | |
| 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 | |
| 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(["" + trans_text, image], stream=True) | |
| res.resolve() | |
| if len(res.candidates) > 0: | |
| content_parts = res.candidates[0].content.parts | |
| decoded_text = content_parts[0].decode("utf-8") | |
| l.append(decoded_text) | |
| if st.button('Report'): | |
| translator = GoogleTranslator(source='en', target='fa') | |
| translated_text = translator.translate(l[0]) | |
| st.markdown(f"<div style='text-align: center; color: blue; font-size: 20px;'>{translated_text}</div>", unsafe_allow_html=True) | |
| else: | |
| st.write("No candidates found in the response.") |