Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Step 1: Import the necessary toolkits
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Step 2: Load our AI Model
|
6 |
+
# This time, we are using a text-classification pipeline with our chosen health model.
|
7 |
+
print("Loading the Health Analysis model...")
|
8 |
+
health_classifier = pipeline(
|
9 |
+
"text-classification",
|
10 |
+
model="shanover/disease_classifier_base"
|
11 |
+
)
|
12 |
+
print("Model loaded successfully!")
|
13 |
+
|
14 |
+
# Step 3: Define the main function for the app
|
15 |
+
# This function takes the user's symptom text and returns a formatted prediction.
|
16 |
+
def analyze_symptoms(symptoms):
|
17 |
+
# Use the pipeline to get the prediction. It returns a list of dictionaries.
|
18 |
+
predictions = health_classifier(symptoms)
|
19 |
+
# For this model, the top prediction is the first item in the list.
|
20 |
+
top_prediction = predictions[0]
|
21 |
+
|
22 |
+
# Extract the predicted disease and the confidence score.
|
23 |
+
disease = top_prediction['label']
|
24 |
+
confidence_score = top_prediction['score']
|
25 |
+
|
26 |
+
# Return the results in a clear, readable string.
|
27 |
+
return f"Predicted Condition: {disease}\nConfidence: {confidence_score:.2f}"
|
28 |
+
|
29 |
+
# Step 4: Define the content for our app
|
30 |
+
# We'll create a title, a detailed description, and a very important disclaimer.
|
31 |
+
app_title = "Symptom to Disease Classifier"
|
32 |
+
app_description = """
|
33 |
+
Enter a list of symptoms, and this AI will predict a possible related medical condition.
|
34 |
+
This tool is for educational purposes only and is based on the 'shanover/disease_classifier_base' model from Hugging Face.
|
35 |
+
"""
|
36 |
+
disclaimer = """
|
37 |
+
**⚠️ IMPORTANT DISCLAIMER ⚠️**
|
38 |
+
This is NOT a medical diagnostic tool. The predictions are generated by an AI model and may be inaccurate.
|
39 |
+
**Always consult with a qualified healthcare professional for any medical advice or diagnosis.**
|
40 |
+
This tool should not be used for any real-world medical decision-making.
|
41 |
+
"""
|
42 |
+
|
43 |
+
# Step 5: Create and Launch the Gradio Web App Interface
|
44 |
+
app = gr.Interface(
|
45 |
+
fn=analyze_symptoms,
|
46 |
+
inputs=gr.Textbox(
|
47 |
+
lines=4,
|
48 |
+
placeholder="e.g., 'I am feeling vomiting, breathlessness, and sweating...'"
|
49 |
+
),
|
50 |
+
outputs="text",
|
51 |
+
title=app_title,
|
52 |
+
description=app_description,
|
53 |
+
article=disclaimer, # The 'article' parameter is great for adding extra text like our disclaimer.
|
54 |
+
examples=[
|
55 |
+
["I have a persistent cough, high fever, and body aches."],
|
56 |
+
["Feeling very thirsty and needing to urinate frequently."],
|
57 |
+
["I have itchy skin with red patches and silver scales."]
|
58 |
+
]
|
59 |
+
)
|
60 |
+
|
61 |
+
# Go live!
|
62 |
+
app.launch()
|