Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load a
|
| 5 |
-
model = pipeline("
|
| 6 |
|
| 7 |
-
# Function to
|
| 8 |
def diagnose(symptoms):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Dynamic prediction
|
| 13 |
-
diagnosis = result['labels'][0] # Top predicted label
|
| 14 |
-
confidence = result['scores'][0] # Confidence score
|
| 15 |
-
|
| 16 |
-
return f"Predicted diagnosis: {diagnosis} with confidence: {confidence:.2f}"
|
| 17 |
|
| 18 |
-
# Triage function
|
| 19 |
def triage(symptoms):
|
| 20 |
if "shortness of breath" in symptoms or "chest pain" in symptoms:
|
| 21 |
return "Urgent: Seek immediate medical attention."
|
|
@@ -26,11 +21,11 @@ def triage(symptoms):
|
|
| 26 |
|
| 27 |
# Combine diagnosis and triage into one function
|
| 28 |
def full_check(symptoms):
|
| 29 |
-
diagnosis = diagnose(symptoms) # Get diagnosis
|
| 30 |
-
severity = triage(symptoms) # Get severity
|
| 31 |
return diagnosis, severity
|
| 32 |
|
| 33 |
-
# Create Gradio interface
|
| 34 |
iface = gr.Interface(
|
| 35 |
fn=full_check,
|
| 36 |
inputs="text",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a pre-trained question-answering model
|
| 5 |
+
model = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 6 |
|
| 7 |
+
# Function to answer based on symptoms
|
| 8 |
def diagnose(symptoms):
|
| 9 |
+
question = f"Given these symptoms: {symptoms}, what is the possible diagnosis?"
|
| 10 |
+
answer = model(question=question, context="The model will use this context to infer the diagnosis.") # Placeholder context
|
| 11 |
+
return answer['answer']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Triage function (same as before)
|
| 14 |
def triage(symptoms):
|
| 15 |
if "shortness of breath" in symptoms or "chest pain" in symptoms:
|
| 16 |
return "Urgent: Seek immediate medical attention."
|
|
|
|
| 21 |
|
| 22 |
# Combine diagnosis and triage into one function
|
| 23 |
def full_check(symptoms):
|
| 24 |
+
diagnosis = diagnose(symptoms) # Get diagnosis from QA model
|
| 25 |
+
severity = triage(symptoms) # Get severity level
|
| 26 |
return diagnosis, severity
|
| 27 |
|
| 28 |
+
# Create the Gradio interface
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=full_check,
|
| 31 |
inputs="text",
|