SymptomChecker / app.py
srinivas-mushroom's picture
Create app.py
b7982f9
raw
history blame
1.45 kB
import gradio as gr
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Load the symptom-disease dataset
df = pd.read_csv("Symptom-severity.csv")
# Create a bag-of-words representation of the symptoms
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(df["Symptom"].values.astype("U"))
y = df["Disease"]
# Train a Naive Bayes classifier on the symptom-disease dataset
clf = MultinomialNB()
clf.fit(X, y)
# Define the chatbot function
def diagnose_disease(symptoms):
# Convert input symptoms to bag-of-words representation
X_new = vectorizer.transform([symptoms])
# Predict the disease using the trained classifier
disease = clf.predict(X_new)[0]
# Get the description of the predicted disease
description = df[df["Disease"] == disease]["Description"].values[0]
return f"The most likely disease based on the symptoms entered is {disease}. {description}"
# Define the input and output interfaces
input_text = gr.inputs.Textbox(label="Enter your symptoms separated by commas")
output_text = gr.outputs.Textbox()
# Create the Gradio interface
gr.Interface(fn=diagnose_disease, inputs=input_text, outputs=output_text,
title="Symptom-based Disease Diagnosis Chatbot",
description="Enter your symptoms separated by commas, and the chatbot will predict the most likely disease.").launch()