File size: 1,196 Bytes
77a690a
6cf9896
 
55c872e
 
6cf9896
93b086c
55c872e
 
 
93b086c
 
 
 
 
 
 
 
 
 
55c872e
93b086c
 
 
 
 
55c872e
 
 
93b086c
7d8680a
55c872e
93b086c
 
55c872e
 
 
 
 
93b086c
7d8680a
6cf9896
77a690a
35766a3
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
35
36
37
38
39
40
41
42
43
44
import gradio as gr
from huggingface_hub import InferenceClient

# Initialize client
client = InferenceClient(model="HuggingFaceH4/zephyr-7b-beta")

def chat_function(message, history):
    messages = [
        {"role": "system", "content": "You are a helpful and professional AI assistant."}
    ]

    for user_msg, bot_msg in history:
        messages.append({"role": "user", "content": user_msg})
        messages.append({"role": "assistant", "content": bot_msg})

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

    response = ""

    for message_obj in client.chat_completion(
        messages=messages,
        max_tokens=512,
        stream=True,
        temperature=0.7,
        top_p=0.95,
    ):
        token = message_obj.choices[0].delta.content or ""
        response += token
        yield response

demo = gr.ChatInterface(
    fn=chat_function,
    title="Premium AI Chatbot",
    description="A high-performance assistant hosted on Hugging Face.",
    examples=[
        "What are the benefits of RPA?",
        "How to optimize SIP investments?",
        "Explain financial planning."
    ],
    cache_examples=False,
)

if __name__ == "__main__":
    demo.launch()