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 AutoModelForSequenceClassification, AutoTokenizer,
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
@@ -15,7 +15,7 @@ def classify_medical_text(txt):
|
|
15 |
return dict(zip(medical_categories, map(float, probs)))
|
16 |
|
17 |
# Load the psychiatric model from Hugging Face
|
18 |
-
psychiatric_model_name = "
|
19 |
psychiatric_tokenizer = AutoTokenizer.from_pretrained(psychiatric_model_name)
|
20 |
psychiatric_model = AutoModelForSequenceClassification.from_pretrained(psychiatric_model_name)
|
21 |
|
@@ -31,10 +31,10 @@ def classify_psychiatric_text(txt):
|
|
31 |
probabilities = torch.softmax(logits, dim=1).squeeze().tolist()
|
32 |
return dict(zip(psychiatric_labels, probabilities))
|
33 |
|
34 |
-
# Load
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
# Chat function for Lifestyle and Nutrition
|
40 |
chat_history = []
|
@@ -61,7 +61,7 @@ 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
|
65 |
lifestyle_msg = gr.Textbox(placeholder="Ask your question here...", label="Your Question")
|
66 |
lifestyle_clear = gr.Button("Clear Chat")
|
67 |
|
@@ -72,6 +72,17 @@ def user_message(input_text):
|
|
72 |
lifestyle_chatbot.append((input_text, response))
|
73 |
return lifestyle_chatbot, ""
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
medical_interface = gr.Interface(
|
76 |
fn=classify_medical_text,
|
77 |
inputs=medical_text,
|
@@ -80,6 +91,7 @@ medical_interface = gr.Interface(
|
|
80 |
description=medical_description,
|
81 |
)
|
82 |
|
|
|
83 |
psychiatric_interface = gr.Interface(
|
84 |
fn=classify_psychiatric_text,
|
85 |
inputs=psychiatric_text,
|
@@ -87,25 +99,11 @@ psychiatric_interface = gr.Interface(
|
|
87 |
examples=psychiatric_examples,
|
88 |
description=psychiatric_description,
|
89 |
)
|
90 |
-
lifestyle_interface = gr.Interface(
|
91 |
-
fn=user_message,
|
92 |
-
inputs=[lifestyle_msg],
|
93 |
-
outputs=[lifestyle_chatbot, lifestyle_msg],
|
94 |
-
live=True,
|
95 |
-
title="Lifestyle and Nutrition Chatbot",
|
96 |
-
description="Ask me anything about fitness, nutrition, or wellness!"
|
97 |
-
)
|
98 |
-
|
99 |
-
with gr.Blocks() as lifestyle_interface:
|
100 |
-
gr.Markdown("## Lifestyle and Nutrition Chatbot")
|
101 |
-
gr.Markdown("Ask me anything about fitness, nutrition, or wellness!")
|
102 |
-
lifestyle_msg.submit(user_message, inputs=[lifestyle_msg], outputs=[lifestyle_chatbot, lifestyle_msg])
|
103 |
-
lifestyle_clear.click(clear_chat, outputs=[lifestyle_chatbot])
|
104 |
|
105 |
# Combine interfaces using Tabs
|
106 |
app = gr.TabbedInterface(
|
107 |
[medical_interface, psychiatric_interface, lifestyle_interface],
|
108 |
-
["Medical
|
109 |
)
|
110 |
|
111 |
-
app.launch(inline=False)
|
|
|
1 |
from fastai.text.all import *
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, BlenderbotForConditionalGeneration, BlenderbotTokenizer
|
3 |
import torch
|
4 |
import gradio as gr
|
5 |
|
|
|
15 |
return dict(zip(medical_categories, map(float, probs)))
|
16 |
|
17 |
# Load the psychiatric model from Hugging Face
|
18 |
+
psychiatric_model_name = "mental/mental-bert-base-uncased" # Replace with the appropriate model
|
19 |
psychiatric_tokenizer = AutoTokenizer.from_pretrained(psychiatric_model_name)
|
20 |
psychiatric_model = AutoModelForSequenceClassification.from_pretrained(psychiatric_model_name)
|
21 |
|
|
|
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 = []
|
|
|
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 |
|
|
|
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 |
description=medical_description,
|
92 |
)
|
93 |
|
94 |
+
# Psychiatric Analysis Interface
|
95 |
psychiatric_interface = gr.Interface(
|
96 |
fn=classify_psychiatric_text,
|
97 |
inputs=psychiatric_text,
|
|
|
99 |
examples=psychiatric_examples,
|
100 |
description=psychiatric_description,
|
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)
|