| 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, |
| top_p = 0.5, |
| temperature = 0.1, |
| stream = True |
| ) |
|
|
| for message in stream: |
| token = message.choices[0].delta.content |
| response += token |
| |
| yield response |
|
|
| chatbot = gr.ChatInterface(respond) |
|
|
| chatbot.launch() |