File size: 820 Bytes
e39f0ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14e9eac
e39f0ca
 
 
14e9eac
e39f0ca
 
 
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
import gradio as gr
from huggingface_hub import InferenceClient

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

def chat_response(message, history):
    messages = []
    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 msg in client.chat_completion(messages, max_tokens=1024, stream=True):
        response += msg.choices[0].delta.content or ""
        yield response

# Yahan se error wali line hamesha ke liye hata di gayi hai
demo = gr.ChatInterface(
    fn=chat_response,
    title="My Smart AI Chatbot",
    description="Main ek AI Assistant hoon. Mujhse kuch bhi puchiye!"
)

demo.launch()