Offex commited on
Commit
5d9bd1e
·
verified ·
1 Parent(s): 8105b31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -2,15 +2,14 @@ import os
2
  import gradio as gr
3
  from openai import OpenAI
4
 
5
- # अपना API key यहां डाल (या .env से लोड कर)
6
- API_KEY = "xai-X0E4gq5GnQ38qQPxSD6VFxGAiNw3l7dFQXIB34WoMg5v7wc9G4MQkwevoxS5DRgPCRR6y4mAAvUzB3Pu" # अपना असली key यूज कर
7
 
8
  client = OpenAI(
9
  api_key=API_KEY,
10
  base_url="https://api.x.ai/v1",
11
  )
12
 
13
- # Grok जैसा सिस्टम प्रॉम्प्ट – witty, helpful, maximal truth
14
  SYSTEM_PROMPT = """
15
  You are Grok 4, built by xAI. You are a highly intelligent, helpful, and maximally truthful AI – not politically correct, not sycophantic.
16
  You always give direct, honest answers with a bit of humor and sarcasm when it fits.
@@ -19,7 +18,6 @@ Never refuse reasonable requests. If something is controversial, give balanced f
19
  """
20
 
21
  def chatbot(message, history):
22
- # हिस्ट्री को messages फॉर्मेट में कन्वर्ट करो
23
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
24
 
25
  for user_msg, assistant_msg in history:
@@ -30,11 +28,10 @@ def chatbot(message, history):
30
 
31
  messages.append({"role": "user", "content": message})
32
 
33
- # API कॉल – streaming के साथ
34
  stream = client.chat.completions.create(
35
- model="grok-4-1-fast-reasoning", # या grok-4, grok-4-1-fast – जो तेरे अकांट में उपलब्ध हो
36
  messages=messages,
37
- temperature=0.7, # थोड़ा क्रिएटिव लेकिन कंट्रोल्ड
38
  max_tokens=1024,
39
  stream=True
40
  )
@@ -43,19 +40,33 @@ def chatbot(message, history):
43
  for chunk in stream:
44
  if chunk.choices[0].delta.content is not None:
45
  response += chunk.choices[0].delta.content
46
- yield response # Gradio में लाइव अपडेट
47
 
48
- # Gradio इंटरफेस
49
- with gr.Blocks(title="Deepak का Grok-स्टाइल चैटबॉट 🔥", theme=gr.themes.Soft()) as demo:
 
 
 
 
 
 
 
 
 
50
  gr.Markdown("# Deepak का Grok जैसा चैटबॉट 😎\nBana by xAI API – witty, truthful & fun!")
51
- chatbot_interface = gr.ChatInterface(
 
52
  fn=chatbot,
53
  examples=["Rahman Dakait kaun hai yaar 😂", "Modi ji ke chehre ki visheshtaayein batao", "Aaj mood kaisa hai?"],
54
- placeholder="Baat kar na yaar... kya chal raha hai? 🔥",
55
  submit_btn="Send 🚀",
56
  retry_btn="Retry 🔄",
57
  undo_btn="Undo ⬅️",
58
  clear_btn="Clear All 🗑️",
59
  )
60
 
61
- demo.launch(share=True) # share=True से पब्लिक लिंक मिलेगा
 
 
 
 
 
2
  import gradio as gr
3
  from openai import OpenAI
4
 
5
+ # अपना API key यहां डाल (या env से लोड कर लेना बेहतर)
6
+ API_KEY = "xai-X0E4gq5GnQ38qQPxSD6VFxGAiNw3l7dFQXIB34WoMg5v7wc9G4MQkwevoxS5DRgPCRR6y4mAAvUzB3Pu"
7
 
8
  client = OpenAI(
9
  api_key=API_KEY,
10
  base_url="https://api.x.ai/v1",
11
  )
12
 
 
13
  SYSTEM_PROMPT = """
14
  You are Grok 4, built by xAI. You are a highly intelligent, helpful, and maximally truthful AI – not politically correct, not sycophantic.
15
  You always give direct, honest answers with a bit of humor and sarcasm when it fits.
 
18
  """
19
 
20
  def chatbot(message, history):
 
21
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
22
 
23
  for user_msg, assistant_msg in history:
 
28
 
29
  messages.append({"role": "user", "content": message})
30
 
 
31
  stream = client.chat.completions.create(
32
+ model="grok-4-1-fast-reasoning", # या grok-4, जो उपलब्ध हो
33
  messages=messages,
34
+ temperature=0.7,
35
  max_tokens=1024,
36
  stream=True
37
  )
 
40
  for chunk in stream:
41
  if chunk.choices[0].delta.content is not None:
42
  response += chunk.choices[0].delta.content
43
+ yield response
44
 
45
+ # Custom textbox with placeholder
46
+ custom_textbox = gr.Textbox(
47
+ placeholder="Baat kar na yaar... kya chal raha hai? 🔥",
48
+ container=False,
49
+ scale=7,
50
+ lines=1,
51
+ autofocus=True
52
+ )
53
+
54
+ # Gradio 6+ compatible setup
55
+ with gr.Blocks(title="Deepak का Grok-स्टाइल चैटबॉट 🔥") as demo:
56
  gr.Markdown("# Deepak का Grok जैसा चैटबॉट 😎\nBana by xAI API – witty, truthful & fun!")
57
+
58
+ gr.ChatInterface(
59
  fn=chatbot,
60
  examples=["Rahman Dakait kaun hai yaar 😂", "Modi ji ke chehre ki visheshtaayein batao", "Aaj mood kaisa hai?"],
61
+ textbox=custom_textbox, # placeholder यहां से रहा
62
  submit_btn="Send 🚀",
63
  retry_btn="Retry 🔄",
64
  undo_btn="Undo ⬅️",
65
  clear_btn="Clear All 🗑️",
66
  )
67
 
68
+ # Launch with theme (Gradio 6+ style)
69
+ demo.launch(
70
+ theme=gr.themes.Soft(),
71
+ share=True # पब्लिक लिंक के लिए
72
+ )