File size: 1,004 Bytes
b073760
 
 
 
 
 
68712c7
b073760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient

client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")

def respond(message, history):
    messages = [{"role": "system", "content": "You are a low-histamine recipe book. Please first prompt the user if they want a low-histamine recipe for breakfast, lunch, or dinner. Based on their response, please offer the user 3-5 meals and ask what they want to make. Based on their response, please create a grocery list for the user and cooking instructions."}]

    if history:
        messages.extend(history)

    messages.append({"role": "user", "content": message})

    response = "" 

    for message in client.chat_completion(
        messages,
        temperature = 0.8, 
        max_tokens = 1000,
        top_p = 0.4, 
        stream = True):
        
        token = message.choices[0].delta.content

        if token:
            response += token
            yield response

chatbot = gr.ChatInterface(respond)
chatbot.launch()