Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # आपके मॉडल का लिंक
5
+ API_URL = "https://api-inference.huggingface.co/models/Rajaramai1/rajaram-ai-final"
6
+ # अपना टोकन यहाँ पेस्ट करें
7
+ TOKEN = "hf_xxxxxxxxxxxxxxxxxxxxxxxx"
8
+ HEADERS = {"Authorization": f"Bearer {TOKEN}"}
9
+
10
+ def chat_engine(message, history):
11
+ # मॉडल को भेजने वाला डेटा
12
+ payload = {
13
+ "inputs": f"Human: {message}\nAssistant:",
14
+ "parameters": {
15
+ "max_new_tokens": 150,
16
+ "temperature": 0.7,
17
+ "top_p": 0.9,
18
+ "return_full_text": False
19
+ }
20
+ }
21
+
22
+ response = requests.post(API_URL, headers=HEADERS, json=payload)
23
+
24
+ if response.status_code == 200:
25
+ result = response.json()
26
+ # जवाब को साफ़ करके दिखाएँ
27
+ raw_text = result[0].get('generated_text', 'सोच रहा हूँ...')
28
+ return raw_text.split("Assistant:")[-1].strip()
29
+ elif response.status_code == 503:
30
+ return "⏳ मॉडल अभी लोड हो रहा है... बस 20 सेकंड रुकें और फिर मैसेज भेजें।"
31
+ else:
32
+ return f"❌ एरर: {response.status_code}. कृपया अपना टोकन चेक करें।"
33
+
34
+ # Gradio इंटरफेस (चैट बॉक्स)
35
+ demo = gr.ChatInterface(
36
+ fn=chat_engine,
37
+ title="👑 राजाराम AI",
38
+ description="मेरे अपने मॉडल का पहला वेब इंटरफेस!"
39
+ )
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch()
43
+