sauvivek's picture
Update app.py
2964452 verified
raw
history blame contribute delete
844 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_name = "thrishala/mental_health_chatbot"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def generate_response(user_input):
inputs = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt")
output = model.generate(inputs, max_length=250, pad_token_id=tokenizer.eos_token_id)
response = tokenizer.decode(output[:, inputs.shape[-1]:][0], skip_special_tokens=True)
return response
interface = gr.Interface(
fn=generate_response,
inputs="text",
outputs="text",
title="Mental Health Chatbot",
description="A chatbot providing empathetic support and resources for mental health."
)
if __name__ == "__main__":
interface.launch()