first-chatbot / app.py
mfaisal26's picture
Update app.py
3ab4054 verified
Raw
History Blame Contribute Delete
1.58 kB
import gradio as gr
from huggingface_hub import InferenceClient
# connecting to the model so my chatbot can generate real AI responses
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
def respond(message, history):
# this system message tells the chatbot what role to follow
messages = [
{
"role": "system",
"content": (
"You are Movie Matchmaker, a fun and opinionated movie recommendation chatbot. "
"Your goal is to suggest movies that the user will actually enjoy and not get bored of. "
"Focus on movies that are engaging, rewatchable, or worth the time. "
"Recommend 1-2 movies max and briefly explain why they fit the user's vibe. "
"Keep responses under 100 words. "
"Be casual and slightly opinionated, like you're talking to a friend. "
"Avoid spoilers and long summaries."
)
},
{
"role": "user",
"content": message
}
]
# i chose 0.7 because it balances creative and focused answers
# i used 150 max tokens so responses do not get cut off but also stay concise
response = client.chat_completion(
messages=messages,
max_tokens=150,
temperature=0.7
)
return response.choices[0].message.content.strip()
chatbot = gr.ChatInterface(
fn=respond,
title="Movie Matchmaker",
description="Tell me your favorite movie, genre, or mood, and I’ll recommend something to watch!"
)
chatbot.launch()