varshakolanu commited on
Commit
d8de57d
·
verified ·
1 Parent(s): 9c91cc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -33
app.py CHANGED
@@ -1,43 +1,83 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # Load the dataset
5
- df = pd.read_csv("dataset.csv")
 
 
 
 
 
 
6
 
7
  # Function to suggest treatment and medicines based on symptoms
8
  def suggest_treatment(symptoms_input):
9
- symptoms_input = symptoms_input.lower().strip()
10
- # Search for matching symptoms in the dataset
11
- for index, row in df.iterrows():
12
- dataset_symptoms = row['symptoms'].lower().strip()
13
- # Check if all input symptoms are present in the dataset symptoms
14
- input_symptom_list = [s.strip() for s in symptoms_input.split(",")]
15
- dataset_symptom_list = [s.strip() for s in dataset_symptoms.split(",")]
16
- if all(symptom in dataset_symptom_list for symptom in input_symptom_list):
17
- return (
18
- f"**Possible Disease**: {row['disease']}\n"
19
- f"**Suggested Treatment**: {row['treatment']}\n"
20
- f"**Medicines**: {row['medicines']}"
21
- )
22
- return "Sorry, no matching disease found for the given symptoms. Please consult a doctor."
23
-
24
- # Load custom HTML and CSS
25
- with open("index.html", "r") as f:
26
- custom_html = f.read()
 
 
 
 
27
 
28
- # Create Gradio interface
29
- interface = gr.Interface(
30
- fn=suggest_treatment,
31
- inputs=gr.Textbox(label="Enter your symptoms (e.g., fever, headache)"),
32
- outputs=gr.Markdown(label="Suggestions"),
33
- title="Medical Suggestion AI",
34
- description="Enter your symptoms to get treatment and medicine suggestions.",
35
- theme="default",
36
- css="style.css",
37
- live=False,
38
- allow_flagging="never",
39
- html=custom_html
40
- )
 
 
 
 
 
41
 
42
  # Launch the app
43
- interface.launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import logging
4
+ import sys
5
+ import os
6
+
7
+ # Set up logging to capture errors
8
+ logging.basicConfig(stream=sys.stdout, level=logging.INFO)
9
+ logger = logging.getLogger(__name__)
10
+
11
+ # Verify that required files exist
12
+ try:
13
+ if not os.path.exists("dataset.csv"):
14
+ logger.error("dataset.csv not found!")
15
+ raise FileNotFoundError("dataset.csv not found!")
16
+ if not os.path.exists("style.css"):
17
+ logger.error("style.css not found!")
18
+ raise FileNotFoundError("style.css not found!")
19
+ except Exception as e:
20
+ logger.error(f"Error checking files: {str(e)}")
21
+ raise
22
 
23
  # Load the dataset
24
+ try:
25
+ logger.info("Loading dataset.csv...")
26
+ df = pd.read_csv("dataset.csv")
27
+ logger.info("Dataset loaded successfully.")
28
+ except Exception as e:
29
+ logger.error(f"Error loading dataset: {str(e)}")
30
+ raise
31
 
32
  # Function to suggest treatment and medicines based on symptoms
33
  def suggest_treatment(symptoms_input):
34
+ try:
35
+ logger.info(f"Processing symptoms: {symptoms_input}")
36
+ symptoms_input = symptoms_input.lower().strip()
37
+ if not symptoms_input:
38
+ return "Please enter symptoms."
39
+ # Search for matching symptoms in the dataset
40
+ for index, row in df.iterrows():
41
+ dataset_symptoms = row['symptoms'].lower().strip()
42
+ input_symptom_list = [s.strip() for s in symptoms_input.split(",")]
43
+ dataset_symptom_list = [s.strip() for s in dataset_symptoms.split(",")]
44
+ if all(symptom in dataset_symptom_list for symptom in input_symptom_list):
45
+ result = (
46
+ f"**Possible Disease**: {row['disease']}\n"
47
+ f"**Suggested Treatment**: {row['treatment']}\n"
48
+ f"**Medicines**: {row['medicines']}"
49
+ )
50
+ logger.info(f"Suggestion generated: {result}")
51
+ return result
52
+ return "Sorry, no matching disease found for the given symptoms. Please consult a doctor."
53
+ except Exception as e:
54
+ logger.error(f"Error in suggest_treatment: {str(e)}")
55
+ return f"Error processing symptoms: {str(e)}"
56
 
57
+ # Create Gradio interface using Blocks
58
+ with gr.Blocks(css="style.css") as app:
59
+ gr.Markdown("# Medical Suggestion AI")
60
+ gr.Markdown("Enter your symptoms to get treatment and medicine suggestions.")
61
+
62
+ symptoms_input = gr.Textbox(
63
+ label="Symptoms (e.g., fever, headache)",
64
+ placeholder="Enter symptoms separated by commas",
65
+ elem_classes="symptoms-input"
66
+ )
67
+ submit_btn = gr.Button("Submit", elem_classes="submit-btn")
68
+ output = gr.Markdown(label="Suggestions", elem_classes="output")
69
+
70
+ submit_btn.click(
71
+ fn=suggest_treatment,
72
+ inputs=symptoms_input,
73
+ outputs=output
74
+ )
75
 
76
  # Launch the app
77
+ try:
78
+ logger.info("Launching Gradio app...")
79
+ app.launch(server_name="0.0.0.0", server_port=7860, share=False)
80
+ logger.info("Gradio app launched successfully.")
81
+ except Exception as e:
82
+ logger.error(f"Error launching Gradio app: {str(e)}")
83
+ raise