Spaces:
Runtime error
Runtime error
Commit
·
b7982f9
1
Parent(s):
1826325
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
| 5 |
+
from sklearn.naive_bayes import MultinomialNB
|
| 6 |
+
|
| 7 |
+
# Load the symptom-disease dataset
|
| 8 |
+
df = pd.read_csv("Symptom-severity.csv")
|
| 9 |
+
|
| 10 |
+
# Create a bag-of-words representation of the symptoms
|
| 11 |
+
vectorizer = CountVectorizer()
|
| 12 |
+
X = vectorizer.fit_transform(df["Symptom"].values.astype("U"))
|
| 13 |
+
y = df["Disease"]
|
| 14 |
+
|
| 15 |
+
# Train a Naive Bayes classifier on the symptom-disease dataset
|
| 16 |
+
clf = MultinomialNB()
|
| 17 |
+
clf.fit(X, y)
|
| 18 |
+
|
| 19 |
+
# Define the chatbot function
|
| 20 |
+
def diagnose_disease(symptoms):
|
| 21 |
+
# Convert input symptoms to bag-of-words representation
|
| 22 |
+
X_new = vectorizer.transform([symptoms])
|
| 23 |
+
|
| 24 |
+
# Predict the disease using the trained classifier
|
| 25 |
+
disease = clf.predict(X_new)[0]
|
| 26 |
+
|
| 27 |
+
# Get the description of the predicted disease
|
| 28 |
+
description = df[df["Disease"] == disease]["Description"].values[0]
|
| 29 |
+
|
| 30 |
+
return f"The most likely disease based on the symptoms entered is {disease}. {description}"
|
| 31 |
+
|
| 32 |
+
# Define the input and output interfaces
|
| 33 |
+
input_text = gr.inputs.Textbox(label="Enter your symptoms separated by commas")
|
| 34 |
+
output_text = gr.outputs.Textbox()
|
| 35 |
+
|
| 36 |
+
# Create the Gradio interface
|
| 37 |
+
gr.Interface(fn=diagnose_disease, inputs=input_text, outputs=output_text,
|
| 38 |
+
title="Symptom-based Disease Diagnosis Chatbot",
|
| 39 |
+
description="Enter your symptoms separated by commas, and the chatbot will predict the most likely disease.").launch()
|