File size: 1,711 Bytes
c4254ca
63ef33f
c4254ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63ef33f
 
c4254ca
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)