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)