RaoMamoon commited on
Commit
7273548
·
verified ·
1 Parent(s): ee58a87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -27
app.py CHANGED
@@ -1,27 +1,54 @@
1
- medicine_data = {
2
- "Paracetamol": {
3
- "Purpose": "Pain relief and fever reduction",
4
- "Used for": "Headaches, muscle pain, colds, flu, and fever"
5
- },
6
- "Ibuprofen": {
7
- "Purpose": "Anti-inflammatory and pain relief",
8
- "Used for": "Arthritis, menstrual pain, muscle pain, and fever"
9
- },
10
- "Amoxicillin": {
11
- "Purpose": "Antibiotic",
12
- "Used for": "Bacterial infections such as pneumonia, bronchitis, and skin infections"
13
- },
14
- "Metformin": {
15
- "Purpose": "Blood sugar control",
16
- "Used for": "Type 2 diabetes management"
17
- },
18
- "Aspirin": {
19
- "Purpose": "Pain relief, anti-inflammatory, and blood thinner",
20
- "Used for": "Headaches, heart attack prevention, and pain relief"
21
- },
22
- "Lisinopril": {
23
- "Purpose": "Blood pressure control",
24
- "Used for": "Hypertension (high blood pressure)"
25
- },
26
- # Add more medicines here...
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # OpenFDA API endpoint
5
+ OPENFDA_API_URL = "https://api.fda.gov/drug/label.json"
6
+
7
+ # Streamlit app
8
+ st.title("Medicine Information Lookup")
9
+ st.write("Enter a medicine name to get information about its purpose, usage, and more.")
10
+
11
+ # User input
12
+ medicine_name = st.text_input("Enter Medicine Name", "").strip()
13
+
14
+ if medicine_name:
15
+ # Fetch data from OpenFDA API
16
+ params = {
17
+ "search": f'generic_name:"{medicine_name}"', # Search by generic name
18
+ "limit": 1 # Limit to 1 result
19
+ }
20
+
21
+ # Show a loading spinner while fetching data
22
+ with st.spinner("Fetching data..."):
23
+ response = requests.get(OPENFDA_API_URL, params=params)
24
+
25
+ # Check if the request was successful
26
+ if response.status_code == 200:
27
+ data = response.json()
28
+ if data.get("results"):
29
+ drug_info = data["results"][0] # Get the first result
30
+ st.subheader(f"Information about {medicine_name}:")
31
+
32
+ # Display purpose
33
+ purpose = drug_info.get("purpose", "Not available")
34
+ st.write(f"**Purpose:** {purpose}")
35
+
36
+ # Display indications and usage
37
+ indications = drug_info.get("indications_and_usage", "Not available")
38
+ st.write(f"**Indications and Usage:** {indications}")
39
+
40
+ # Display warnings
41
+ warnings = drug_info.get("warnings", "Not available")
42
+ st.write(f"**Warnings:** {warnings}")
43
+
44
+ # Display dosage and administration
45
+ dosage = drug_info.get("dosage_and_administration", "Not available")
46
+ st.write(f"**Dosage and Administration:** {dosage}")
47
+
48
+ # Display side effects
49
+ side_effects = drug_info.get("adverse_reactions", "Not available")
50
+ st.write(f"**Side Effects:** {side_effects}")
51
+ else:
52
+ st.warning("Medicine not found in the database. Please try another name.")
53
+ else:
54
+ st.error("Failed to fetch data from the API. Please try again later.")