Spaces:
Sleeping
Sleeping
import streamlit as st | |
from googleapiclient.discovery import build | |
# Create a Streamlit app | |
st.title("AI Symptom Checker") | |
st.write("Please enter your symptoms:") | |
# Create a text input field | |
symptoms_input = st.text_input("Symptoms:", value="", max_chars=500) | |
# Create a button to trigger the API call | |
submit_button = st.button("Check Symptoms") | |
# Define the Google Gemini API call function | |
def 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 function | |
def 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 response | |
def 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 secrets file | |
api_key = st.secrets["GEMINI_API_KEY"] | |
# Call the main function when the button is clicked | |
if submit_button: | |
symptoms = symptoms_input | |
response_list = check_symptoms(symptoms, api_key) | |
st.write("Possible conditions:") | |
for response in response_list: | |
st.write(response) |