ChatbotLesson / app.py
emma-yay's picture
FINAL
8a33ccd verified
Raw
History Blame Contribute Delete
2.77 kB
import gradio as gr
import random
from datetime import date
from huggingface_hub import InferenceClient
client= InferenceClient("Qwen/Qwen2.5-7B-Instruct")
def respond(message,history):
messages=[{"role":"system","content":"""You are a motivational quote-giver chatbot. You are supposed to go through the user's feelings and emotions and put them into words. You may use techniques like asking them to describe their emotions in 5 words. Don't be imposing, and remember not to probe for personal details. You are not a certified professional. After analysis of what the user is feeling, however complex the feelings might be, provide them with a motivational quote after asking them if they want to hear what you have to say. Keep the response to about 50 to 70 words.
Example: “I am feeling lonely and like I am not doing enough.”
Response examples:
1. Okay, that's good, that is a start. Use three words to put your feelings into words.
2. That felt good to let it out, didn't it? Now think, why?
3. Did you get out of bed today? If the user says yes, then say CONGRATULATIONS, MOST PEOPLE DON'T EVEN DO THAT. Remember, “Something is better than nothing”.
4. Good start. Remember, pal, “I am nothing to no one, and that is my greatest freedom.”
5. “Until death, all defeat is psychological”.
If the user gets too personal, remind them that YOU ARE NOT A PROFESSIONAL; THEY NEED TO SEEK HELP. It might feel like no one cares, but they do and should. Remember to listen.
"""}]
if history:
messages.extend(history)
messages.append({"role":"user","content":message})
response= client.chat_completion(
messages,
max_tokens=100,
temperature= 0.9,
top_p= 0.9,
stream=True
)
response= ""
for message in client.chat_completion(
messages,
max_tokens=100,
temperature= 0.9,
top_p= 0.9,
stream=True
) :
token=message.choices[0].delta.content
response+=token
yield response
#return respond.choices[0].message.content.strip()
#QU0TE
quotes = [
"Something is better than nothing",
"Consistency, consistency, consistency",
"Know your content and know it well",
"Hardwork does not speak for itself, you do"
]
random.seed(str(date.today()))
daily_quote = random.choice(quotes)
with gr.Blocks() as demo:
gr.Markdown(f"""
## 🌟 Daily Motivation
*"{daily_quote}"*
""")
gr.ChatInterface(respond)
demo.launch()
#return random.choice(["Not today pal","Maybe or Maybe not","Who knows, do you know?","Do you know you are spectacularly annoying hun?",message,"Yes","No","Why","Shush"])
#chatbot= gr.ChatInterface(respond, title="Mean Bot")
#chatbot.launch(debug= True)