Obotu commited on
Commit
fb132ef
1 Parent(s): bcff419

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -14
app.py CHANGED
@@ -1,34 +1,58 @@
 
1
  import streamlit as st
2
- from transformers import pipeline
3
  import requests
4
  from geopy.geocoders import Nominatim
5
 
6
-
7
  API_URL = "https://api-inference.huggingface.co/models/dmis-lab/biobert-base-cased-v1.1"
8
- headers = {"Authorization": "secret"}
9
 
 
10
  def query(payload):
11
  response = requests.post(API_URL, headers=headers, json=payload)
12
- return response.json()
13
-
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def main():
16
  st.title("Healthcare Companion")
17
  st.write("This app provides healthcare guidance, prescription information, and locates nearby clinics or pharmacies.")
18
 
19
- # User input for medical question
20
- question = st.text_input("Enter your medical question:")
21
- if question:
22
- context = "General medical context." # Adjust this as needed
23
- result = query({"inputs": {"question": question, "context": context}})
24
- st.write("**Answer:**")
25
- st.write(result.get('answer', "Sorry, I don't know the answer."))
 
 
 
 
 
 
 
26
 
27
  # User input for address to find nearby clinics/pharmacies
28
  address = st.text_input("Enter your address to find nearby clinics/pharmacies:")
29
  if address:
30
  location = find_nearby_clinics(address)
31
- st.write(f"**Nearby Clinics/Pharmacies (Coordinates):** {location}")
 
32
 
33
  # Additional features like prescription info can be added similarly
34
 
 
1
+
2
  import streamlit as st
 
3
  import requests
4
  from geopy.geocoders import Nominatim
5
 
6
+ # Set your Hugging Face API URL and API key
7
  API_URL = "https://api-inference.huggingface.co/models/dmis-lab/biobert-base-cased-v1.1"
8
+ headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_API_KEY"}
9
 
10
+ # Function to query the Hugging Face model
11
  def query(payload):
12
  response = requests.post(API_URL, headers=headers, json=payload)
13
+ if response.status_code == 200:
14
+ return response.json()
15
+ else:
16
+ st.error("Error: Unable to fetch response from model")
17
+ st.error(response.text)
18
+ return None
19
+
20
+ # Function to find nearby clinics/pharmacies using geopy
21
+ def find_nearby_clinics(address):
22
+ geolocator = Nominatim(user_agent="healthcare_companion")
23
+ location = geolocator.geocode(address)
24
+ if location:
25
+ return (location.latitude, location.longitude)
26
+ else:
27
+ st.error("Error: Address not found")
28
+ return None
29
+
30
+ # Main function to create the Streamlit app
31
  def main():
32
  st.title("Healthcare Companion")
33
  st.write("This app provides healthcare guidance, prescription information, and locates nearby clinics or pharmacies.")
34
 
35
+ # User input for medical symptoms
36
+ symptoms = st.text_area("Enter your symptoms (e.g., 'I am having a cough, weak knee, swollen eyes'):")
37
+ if symptoms:
38
+ context = """
39
+ This is a healthcare question and answer platform. The following text contains typical symptoms, treatments, and medical conditions commonly asked about in healthcare settings.
40
+ For example, symptoms of COVID-19 include fever, dry cough, and tiredness. Treatment options for hypertension include lifestyle changes and medications. The platform is designed to assist with general medical inquiries.
41
+ """
42
+ payload = {"inputs": {"question": symptoms, "context": context}}
43
+ st.write(f"Debug: Payload sent to model: {payload}") # Debugging: Check payload
44
+ result = query(payload)
45
+ st.write(f"Debug: Response from model: {result}") # Debugging: Check response
46
+ if result:
47
+ st.write("**Medical Advice:**")
48
+ st.write(result.get('answer', "Sorry, I don't have information on that."))
49
 
50
  # User input for address to find nearby clinics/pharmacies
51
  address = st.text_input("Enter your address to find nearby clinics/pharmacies:")
52
  if address:
53
  location = find_nearby_clinics(address)
54
+ if location:
55
+ st.write(f"**Nearby Clinics/Pharmacies (Coordinates):** {location}")
56
 
57
  # Additional features like prescription info can be added similarly
58