Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,37 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
"
|
| 6 |
-
|
| 7 |
-
"Used for": "Headaches, muscle pain, colds, flu, and fever"
|
| 8 |
-
},
|
| 9 |
-
"Ibuprofen": {
|
| 10 |
-
"Purpose": "Anti-inflammatory and pain relief",
|
| 11 |
-
"Used for": "Arthritis, menstrual pain, muscle pain, and fever"
|
| 12 |
-
},
|
| 13 |
-
"Amoxicillin": {
|
| 14 |
-
"Purpose": "Antibiotic",
|
| 15 |
-
"Used for": "Bacterial infections such as pneumonia, bronchitis, and skin infections"
|
| 16 |
-
},
|
| 17 |
-
"Metformin": {
|
| 18 |
-
"Purpose": "Blood sugar control",
|
| 19 |
-
"Used for": "Type 2 diabetes management"
|
| 20 |
-
}
|
| 21 |
-
}
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
if selected_medicine in medicine_data:
|
| 34 |
-
st.subheader(f"Information about {selected_medicine}:")
|
| 35 |
-
st.write(f"**Purpose:** {medicine_data[selected_medicine]['Purpose']}")
|
| 36 |
-
st.write(f"**Used for:** {medicine_data[selected_medicine]['Used for']}")
|
| 37 |
-
else:
|
| 38 |
-
st.warning("Medicine not found in the database. Please try another name.")
|
| 39 |
-
|
| 40 |
-
# Optional: Add a search bar for manual input
|
| 41 |
-
st.write("---")
|
| 42 |
-
st.write("Alternatively, type the medicine name below:")
|
| 43 |
-
manual_input = st.text_input("Medicine Name (manual input)", "").strip().capitalize()
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
else:
|
| 51 |
-
st.warning("
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
+
# Function to fetch medicine information from OpenFDA API
|
| 5 |
+
def get_medicine_info(medicine_name):
|
| 6 |
+
url = f"https://api.fda.gov/drug/label.json?search=openfda.brand_name:{medicine_name}&limit=1"
|
| 7 |
+
response = requests.get(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
if response.status_code == 200:
|
| 10 |
+
data = response.json()
|
| 11 |
+
if "results" in data:
|
| 12 |
+
result = data["results"][0]
|
| 13 |
+
purpose = result.get("purpose", ["No purpose information available"])[0]
|
| 14 |
+
indications = result.get("indications_and_usage", ["No usage information available"])[0]
|
| 15 |
+
return purpose, indications
|
| 16 |
+
return None, None
|
| 17 |
|
| 18 |
+
# Streamlit UI
|
| 19 |
+
st.title("Global Medicine Information Lookup")
|
| 20 |
+
st.write("Enter a medicine name to get real-time information from OpenFDA.")
|
| 21 |
|
| 22 |
+
# User input
|
| 23 |
+
medicine_name = st.text_input("Enter Medicine Name", "").strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Fetch and display information
|
| 26 |
+
if st.button("Search"):
|
| 27 |
+
if medicine_name:
|
| 28 |
+
purpose, indications = get_medicine_info(medicine_name)
|
| 29 |
+
if purpose or indications:
|
| 30 |
+
st.subheader(f"Information about {medicine_name}:")
|
| 31 |
+
st.write(f"**Purpose:** {purpose}")
|
| 32 |
+
st.write(f"**Used for:** {indications}")
|
| 33 |
+
else:
|
| 34 |
+
st.warning("Medicine not found in the OpenFDA database. Try another name.")
|
| 35 |
else:
|
| 36 |
+
st.warning("Please enter a medicine name.")
|
| 37 |
+
|