RaoMamoon commited on
Commit
4145921
·
verified ·
1 Parent(s): 1cf3e3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -44
app.py CHANGED
@@ -1,51 +1,37 @@
1
  import streamlit as st
 
2
 
3
- # Sample medicine database
4
- medicine_data = {
5
- "Paracetamol": {
6
- "Purpose": "Pain relief and fever reduction",
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
- # Streamlit app
24
- st.title("Medicine Information Lookup")
25
- st.write("Enter a medicine name to get information about its purpose and usage.")
 
 
 
 
 
26
 
27
- # Dropdown for medicine selection
28
- medicine_list = list(medicine_data.keys())
29
- selected_medicine = st.selectbox("Select or type a medicine name:", medicine_list)
30
 
31
- # Display information if found
32
- if selected_medicine:
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
- if manual_input:
46
- if manual_input in medicine_data:
47
- st.subheader(f"Information about {manual_input}:")
48
- st.write(f"**Purpose:** {medicine_data[manual_input]['Purpose']}")
49
- st.write(f"**Used for:** {medicine_data[manual_input]['Used for']}")
 
 
 
 
 
50
  else:
51
- st.warning("Medicine not found in the database. Please try another name.")
 
 
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
+