Spaces:
Sleeping
Sleeping
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import streamlit as st
# Create a Streamlit appst.title("AI Symptom Checker")st.write("Please enter your symptoms:")
# Create a text input fieldsymptoms_input = st.text_input("Symptoms:", value="", max_chars=500)
# Create a button to trigger the API callsubmit_button = st.button("Check Symptoms")
# Define the Google Gemini API call functiondef call_gemini_api(symptoms, api_key): client = build('gemini', 'v1', developerKey=api_key) request = { 'query': symptoms, 'languageCode': 'en-US', 'maxResults': 10 } response = client.health().symptomChecker().query(body=request).execute() results = response.get('results', []) return results
# Define the response processing functiondef process_response(results): top_results = results[:3] response_list = [] for result in top_results: condition_name = result.get('condition', {}).get('name') probability = result.get('probability') response_string = f"**{condition_name}**: {probability:.2f}%" response_list.append(response_string) return response_list
# Define the main function to call the API and process the responsedef check_symptoms(symptoms, api_key): results = call_gemini_api(symptoms, api_key) response_list = process_response(results) return response_list
# Get the API key from the environment variablesapi_key = st.secrets["AIzaSyBKkDeuMYrYSvwiRX4eyqJ8Vy8xfVwPfGQ"]
# Call the main function when the button is clickedif submit_button: symptoms = symptoms_input response_list = check_symptoms(symptoms, api_key) st.write("Possible conditions:") for response in response_list: st.write(response)app.pyAdded+51