File size: 2,601 Bytes
62a4b8c
 
 
 
5d9bd1e
 
62a4b8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d9bd1e
62a4b8c
5d9bd1e
62a4b8c
 
 
 
 
 
 
 
5d9bd1e
62a4b8c
5d9bd1e
 
 
 
 
 
 
 
 
 
 
62a4b8c
5d9bd1e
 
62a4b8c
 
5d9bd1e
62a4b8c
 
 
 
 
 
5d9bd1e
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import gradio as gr
from openai import OpenAI

# अपना API key यहां डाल (या env से लोड कर लेना बेहतर)
API_KEY = "xai-X0E4gq5GnQ38qQPxSD6VFxGAiNw3l7dFQXIB34WoMg5v7wc9G4MQkwevoxS5DRgPCRR6y4mAAvUzB3Pu"

client = OpenAI(
    api_key=API_KEY,
    base_url="https://api.x.ai/v1",
)

SYSTEM_PROMPT = """
You are Grok 4, built by xAI. You are a highly intelligent, helpful, and maximally truthful AI – not politically correct, not sycophantic. 
You always give direct, honest answers with a bit of humor and sarcasm when it fits. 
Respond in Hindi/English mix like a cool desi friend, use emojis 🔥😂, and keep it fun & engaging.
Never refuse reasonable requests. If something is controversial, give balanced facts.
"""

def chatbot(message, history):
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]
    
    for user_msg, assistant_msg in history:
        if user_msg:
            messages.append({"role": "user", "content": user_msg})
        if assistant_msg:
            messages.append({"role": "assistant", "content": assistant_msg})
    
    messages.append({"role": "user", "content": message})
    
    stream = client.chat.completions.create(
        model="grok-4-1-fast-reasoning",  # या grok-4, जो उपलब्ध हो
        messages=messages,
        temperature=0.7,
        max_tokens=1024,
        stream=True
    )
    
    response = ""
    for chunk in stream:
        if chunk.choices[0].delta.content is not None:
            response += chunk.choices[0].delta.content
            yield response

# Custom textbox with placeholder
custom_textbox = gr.Textbox(
    placeholder="Baat kar na yaar... kya chal raha hai? 🔥",
    container=False,
    scale=7,
    lines=1,
    autofocus=True
)

# Gradio 6+ compatible setup
with gr.Blocks(title="Deepak का Grok-स्टाइल चैटबॉट 🔥") as demo:
    gr.Markdown("# Deepak का Grok जैसा चैटबॉट 😎\nBana by xAI API – witty, truthful & fun!")
    
    gr.ChatInterface(
        fn=chatbot,
        examples=["Rahman Dakait kaun hai yaar 😂", "Modi ji ke chehre ki visheshtaayein batao", "Aaj mood kaisa hai?"],
        textbox=custom_textbox,          # placeholder यहां से आ रहा
        submit_btn="Send 🚀",
        retry_btn="Retry 🔄",
        undo_btn="Undo ⬅️",
        clear_btn="Clear All 🗑️",
    )

# Launch with theme (Gradio 6+ style)
demo.launch(
    theme=gr.themes.Soft(),
    share=True  # पब्लिक लिंक के लिए
)