Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Create a Streamlit app
|
| 4 |
+
st.title("AI Symptom Checker")
|
| 5 |
+
st.write("Please enter your symptoms:")
|
| 6 |
+
|
| 7 |
+
# Create a text input field
|
| 8 |
+
symptoms_input = st.text_input("Symptoms:", value="", max_chars=500)
|
| 9 |
+
|
| 10 |
+
# Create a button to trigger the API call
|
| 11 |
+
submit_button = st.button("Check Symptoms")
|
| 12 |
+
|
| 13 |
+
# Define the Google Gemini API call function
|
| 14 |
+
def call_gemini_api(symptoms, api_key):
|
| 15 |
+
client = build('gemini', 'v1', developerKey=api_key)
|
| 16 |
+
request = {
|
| 17 |
+
'query': symptoms,
|
| 18 |
+
'languageCode': 'en-US',
|
| 19 |
+
'maxResults': 10
|
| 20 |
+
}
|
| 21 |
+
response = client.health().symptomChecker().query(body=request).execute()
|
| 22 |
+
results = response.get('results', [])
|
| 23 |
+
return results
|
| 24 |
+
|
| 25 |
+
# Define the response processing function
|
| 26 |
+
def process_response(results):
|
| 27 |
+
top_results = results[:3]
|
| 28 |
+
response_list = []
|
| 29 |
+
for result in top_results:
|
| 30 |
+
condition_name = result.get('condition', {}).get('name')
|
| 31 |
+
probability = result.get('probability')
|
| 32 |
+
response_string = f"**{condition_name}**: {probability:.2f}%"
|
| 33 |
+
response_list.append(response_string)
|
| 34 |
+
return response_list
|
| 35 |
+
|
| 36 |
+
# Define the main function to call the API and process the response
|
| 37 |
+
def check_symptoms(symptoms, api_key):
|
| 38 |
+
results = call_gemini_api(symptoms, api_key)
|
| 39 |
+
response_list = process_response(results)
|
| 40 |
+
return response_list
|
| 41 |
+
|
| 42 |
+
# Get the API key from the environment variables
|
| 43 |
+
api_key = st.secrets["AIzaSyBKkDeuMYrYSvwiRX4eyqJ8Vy8xfVwPfGQ"]
|
| 44 |
+
|
| 45 |
+
# Call the main function when the button is clicked
|
| 46 |
+
if submit_button:
|
| 47 |
+
symptoms = symptoms_input
|
| 48 |
+
response_list = check_symptoms(symptoms, api_key)
|
| 49 |
+
st.write("Possible conditions:")
|
| 50 |
+
for response in response_list:
|
| 51 |
+
st.write(response)
|