Spaces:
Runtime error
Runtime error
srinivas-mushroom
commited on
Commit
•
f3f7a22
1
Parent(s):
5f7cea6
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,30 @@
|
|
1 |
-
import
|
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 |
-
|
11 |
-
|
12 |
-
X = vectorizer.fit_transform(df["Symptom"].values.astype("U"))
|
13 |
-
y = df["Disease"]
|
14 |
|
15 |
-
|
16 |
-
clf = MultinomialNB()
|
17 |
-
clf.fit(X, y)
|
18 |
|
19 |
-
|
20 |
-
def diagnose_disease(symptoms):
|
21 |
-
# Convert input symptoms to bag-of-words representation
|
22 |
-
X_new = vectorizer.transform([symptoms])
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
description = df[df["Disease"] == disease]["Description"].values[0]
|
29 |
|
30 |
-
|
|
|
|
|
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 |
-
|
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()
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext")
|
4 |
+
model = AutoModelForQuestionAnswering.from_pretrained("microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext")
|
|
|
|
|
5 |
|
6 |
+
import torch
|
|
|
|
|
7 |
|
8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
9 |
|
10 |
+
def biomedical_chatbot(user_message):
|
11 |
+
# Tokenize the user's message
|
12 |
+
inputs = tokenizer.encode_plus(user_message, add_special_tokens=True, return_tensors="pt").to(device)
|
13 |
+
|
14 |
+
# Generate a response using the pre-trained model
|
15 |
+
answer_start_scores, answer_end_scores = model(**inputs)
|
16 |
+
answer_start = torch.argmax(answer_start_scores)
|
17 |
+
answer_end = torch.argmax(answer_end_scores) + 1
|
18 |
+
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][answer_start:answer_end]))
|
19 |
+
|
20 |
+
# Return the response
|
21 |
+
return answer
|
22 |
|
23 |
+
import gradio as gr
|
|
|
24 |
|
25 |
+
gradio_interface = gr.Interface(fn=biomedical_chatbot,
|
26 |
+
inputs=gr.inputs.Textbox(placeholder="Enter your message here..."),
|
27 |
+
outputs=gr.outputs.Textbox())
|
28 |
|
|
|
|
|
|
|
29 |
|
30 |
+
gradio_interface.launch()
|
|
|
|
|
|