Spaces:
Runtime error
Runtime error
File size: 1,450 Bytes
b7982f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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()
|