Spaces:
Sleeping
Sleeping
File size: 1,124 Bytes
81a2ae6 56226b9 b746dc4 a0428bd 56226b9 a0428bd b746dc4 a0428bd b746dc4 81a2ae6 a0428bd 81a2ae6 b746dc4 81a2ae6 a0428bd b746dc4 81a2ae6 b915000 a0428bd b915000 cf7a2e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
# Load chatbot model
chatbot_model = "microsoft/DialoGPT-medium"
tokenizer = AutoTokenizer.from_pretrained(chatbot_model)
model = AutoModelForCausalLM.from_pretrained(chatbot_model)
# Load emotion detection model
emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
def generate_response(user_input):
# Generate chatbot response
input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors="pt")
output = model.generate(input_ids, max_length=200, pad_token_id=tokenizer.eos_token_id)
response = tokenizer.decode(output[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
# Detect emotion
emotion_result = emotion_pipeline(user_input)
emotion = emotion_result[0]["label"]
return response, emotion
iface = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(label="Enter your message"),
outputs=[gr.Textbox(label="Chatbot Response"), gr.Textbox(label="Emotion Detected")],
live=True
)
iface.launch() |