import gradio as gr from huggingface_hub import InferenceClient client = InferenceClient(model="Qwen/Qwen2.5-7B-Instruct") def respond(message, history): response = "" messages = [{"role": "system", "content": "You are a friendly chatbot, tasked with helping the user develop baking recipes, provide substituions, and give them conversions for measurements. Keep responses under 250 words unless the user explicitly asks for more detail. An example of a response: That recipe for biscuits sounds great. Since you don't have any buttermilk, use the following ratio: 2 teaspoons white vinegar or fresh lemon juice and 1 cup minus 2 teaspoons (about 235ml) whole milk. Let me know if I can be of any assistance!"}] if history: messages.extend(history) messages.append({"role": "user", "content": message}) stream = client.chat_completion( messages, max_tokens=350, # I increased the amount of max_tokens to get longer messages without getting cut off. I orginally tested values like 50, 100, and 250, before settling on 350. top_p = 0.5, # I decrease the top_p parameter. I wanted to ensure accuracy while ensuring there were a variety of responses for different requests. I tested the value 1 before settling on 0.5. temperature = 0.1, # I decreased the temperature parameter - I wanted to make sure the answers being outputted were as accurate, and nonrandom as possible. I orginally tested values like 1, 0.8, and 0.5. stream = True ) for message in stream: token = message.choices[0].delta.content response += token yield response chatbot = gr.ChatInterface(respond) chatbot.launch()