File size: 798 Bytes
c127950
0897689
c127950
6cbb926
c127950
cfea855
 
 
 
 
fa6182f
6cbb926
cfea855
 
 
 
 
 
 
 
 
6cbb926
 
 
cfea855
6cbb926
 
 
cfea855
 
6cbb926
91e8cf6
b25c66c
91e8cf6
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
31
32
33
34
import gradio as gr
from huggingface_hub import InferenceClient

client = InferenceClient("google/gemma-1.1-2b-it")

def respond(
    message,
    history: list[tuple[str, str]],
    max_tokens
):
    messages = []

    for val in history:
        if val[0]:
            messages.append({"role": "user", "content": val[0]})
        if val[1]:
            messages.append({"role": "assistant", "content": val[1]})

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

    response = ""

    for message in client.chat_completion(
        messages,
        max_tokens=1024,
        stream=True
    ):
        token = message.choices[0].delta.content
        response += token
        yield response

demo = gr.ChatInterface(respond, description="# Chat With AI faster than groq")

demo.launch()