Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import transformers
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Function to load model and process inputs
|
6 |
+
def chatbot(input_text):
|
7 |
+
# Load a pre-trained mental health model (e.g., the one you selected: 'mental_health_chatbot')
|
8 |
+
model_name = "thrishala/mental_health_chatbot" # Update with your selected model
|
9 |
+
model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
|
11 |
+
|
12 |
+
# Process input and generate response
|
13 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
14 |
+
outputs = model.generate(**inputs)
|
15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
|
17 |
+
return response
|
18 |
+
|
19 |
+
# Define the Gradio interface
|
20 |
+
interface = gr.Interface(fn=chatbot, inputs="text", outputs="text")
|
21 |
+
|
22 |
+
# Launch the Gradio app
|
23 |
+
interface.launch()
|