Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from fastai.text.all import *
|
2 |
-
from transformers import
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
@@ -31,27 +31,6 @@ def classify_psychiatric_text(txt):
|
|
31 |
probabilities = torch.softmax(logits, dim=1).squeeze().tolist()
|
32 |
return dict(zip(psychiatric_labels, probabilities))
|
33 |
|
34 |
-
# # Load BlenderBot for Lifestyle and Nutrition Chatbot
|
35 |
-
# blender_model_name = "facebook/blenderbot-3B" # Pre-trained BlenderBot 3B model
|
36 |
-
# blender_tokenizer = BlenderbotTokenizer.from_pretrained(blender_model_name)
|
37 |
-
# blender_model = BlenderbotForConditionalGeneration.from_pretrained(blender_model_name)
|
38 |
-
|
39 |
-
# Chat function for Lifestyle and Nutrition
|
40 |
-
chat_history = []
|
41 |
-
|
42 |
-
# def chatbot_response(user_input):
|
43 |
-
# global chat_history
|
44 |
-
# new_input_ids = blender_tokenizer.encode(user_input + blender_tokenizer.eos_token, return_tensors='pt')
|
45 |
-
# bot_input_ids = torch.cat([chat_history, new_input_ids], dim=-1) if chat_history else new_input_ids
|
46 |
-
# chat_history = blender_model.generate(bot_input_ids, max_length=1000, pad_token_id=blender_tokenizer.eos_token_id)
|
47 |
-
# response = blender_tokenizer.decode(chat_history[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
|
48 |
-
# return response
|
49 |
-
|
50 |
-
# def clear_chat():
|
51 |
-
# global chat_history
|
52 |
-
# chat_history = []
|
53 |
-
# return []
|
54 |
-
|
55 |
# Gradio Interfaces
|
56 |
medical_text = gr.Textbox(lines=2, label='Describe your symptoms in detail')
|
57 |
medical_label = gr.Label()
|
@@ -61,28 +40,6 @@ psychiatric_text = gr.Textbox(lines=2, label='Describe your mental health concer
|
|
61 |
psychiatric_label = gr.Label()
|
62 |
psychiatric_examples = ['I feel hopeless and have no energy.', 'I am unable to concentrate and feel anxious all the time.', 'I have recurring intrusive thoughts.']
|
63 |
|
64 |
-
lifestyle_chatbot = gr.Chatbot(label="Chat with me about diet and nutrition!")
|
65 |
-
lifestyle_msg = gr.Textbox(placeholder="Ask your question here...", label="Your Question")
|
66 |
-
lifestyle_clear = gr.Button("Clear Chat")
|
67 |
-
|
68 |
-
def user_message(input_text):
|
69 |
-
if not input_text.strip():
|
70 |
-
return lifestyle_chatbot, "Please enter a question."
|
71 |
-
response = chatbot_response(input_text)
|
72 |
-
lifestyle_chatbot.append((input_text, response))
|
73 |
-
return lifestyle_chatbot, ""
|
74 |
-
|
75 |
-
# Lifestyle & Nutrition Interface
|
76 |
-
lifestyle_interface = gr.Interface(
|
77 |
-
fn=user_message,
|
78 |
-
inputs=[lifestyle_msg],
|
79 |
-
outputs=[lifestyle_chatbot, lifestyle_msg],
|
80 |
-
live=True,
|
81 |
-
title="Nutritionist Chatbot",
|
82 |
-
description="Ask me anything about diet, food, and nutrition!"
|
83 |
-
)
|
84 |
-
|
85 |
-
# Medical Diagnosis Interface
|
86 |
medical_interface = gr.Interface(
|
87 |
fn=classify_medical_text,
|
88 |
inputs=medical_text,
|
@@ -91,7 +48,6 @@ medical_interface = gr.Interface(
|
|
91 |
description=medical_description,
|
92 |
)
|
93 |
|
94 |
-
# Psychiatric Analysis Interface
|
95 |
psychiatric_interface = gr.Interface(
|
96 |
fn=classify_psychiatric_text,
|
97 |
inputs=psychiatric_text,
|
@@ -101,9 +57,5 @@ psychiatric_interface = gr.Interface(
|
|
101 |
)
|
102 |
|
103 |
# Combine interfaces using Tabs
|
104 |
-
app = gr.TabbedInterface(
|
105 |
-
[medical_interface, psychiatric_interface, lifestyle_interface],
|
106 |
-
["Medical Diagnosis", "Psychiatric Analysis", "Lifestyle & Nutrition Chat"]
|
107 |
-
)
|
108 |
-
|
109 |
app.launch(inline=False)
|
|
|
1 |
from fastai.text.all import *
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
|
|
31 |
probabilities = torch.softmax(logits, dim=1).squeeze().tolist()
|
32 |
return dict(zip(psychiatric_labels, probabilities))
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Gradio Interfaces
|
35 |
medical_text = gr.Textbox(lines=2, label='Describe your symptoms in detail')
|
36 |
medical_label = gr.Label()
|
|
|
40 |
psychiatric_label = gr.Label()
|
41 |
psychiatric_examples = ['I feel hopeless and have no energy.', 'I am unable to concentrate and feel anxious all the time.', 'I have recurring intrusive thoughts.']
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
medical_interface = gr.Interface(
|
44 |
fn=classify_medical_text,
|
45 |
inputs=medical_text,
|
|
|
48 |
description=medical_description,
|
49 |
)
|
50 |
|
|
|
51 |
psychiatric_interface = gr.Interface(
|
52 |
fn=classify_psychiatric_text,
|
53 |
inputs=psychiatric_text,
|
|
|
57 |
)
|
58 |
|
59 |
# Combine interfaces using Tabs
|
60 |
+
app = gr.TabbedInterface([medical_interface, psychiatric_interface], ["Medical Diagnosis", "Psychiatric Analysis"])
|
|
|
|
|
|
|
|
|
61 |
app.launch(inline=False)
|