Update app.py
Browse files
app.py
CHANGED
|
@@ -3,34 +3,40 @@ import requests
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
def monster_chat(message, history):
|
| 6 |
-
# ืืืื
|
| 7 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
payload = {
|
| 10 |
-
"inputs":
|
| 11 |
-
"parameters": {"max_new_tokens":
|
| 12 |
}
|
| 13 |
|
| 14 |
try:
|
| 15 |
-
response = requests.post(API_URL, json=payload, timeout=
|
| 16 |
|
| 17 |
-
#
|
| 18 |
if response.status_code == 503:
|
| 19 |
time.sleep(5)
|
| 20 |
-
response = requests.post(API_URL, json=payload, timeout=
|
| 21 |
|
| 22 |
result = response.json()
|
| 23 |
|
|
|
|
| 24 |
if isinstance(result, list) and len(result) > 0:
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
except:
|
| 28 |
-
return "
|
| 29 |
|
| 30 |
-
#
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
-
gr.Markdown("# ๐พ
|
| 33 |
gr.ChatInterface(fn=monster_chat)
|
| 34 |
|
| 35 |
-
# ืืขืืจื ื ืืช ื-theme ืืคื, ืืืืืง ืืื ืฉืืฉืืืื ืืืงืฉื
|
| 36 |
demo.launch()
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
def monster_chat(message, history):
|
| 6 |
+
# ืืืชืืืช ืืืืืืงืช ืฉื ืืืืื ืืืฆืืืื ืืกื ืฉืื
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/Jackrong/Qwen3.5-27B-Claude-4.6-Opus-Reasoning-Distilled"
|
| 8 |
+
|
| 9 |
+
# ืืืืจืช ืืืืขืช ืืืขืจืืช ืืื ืฉืืืืจ ืขืืจืืช
|
| 10 |
+
prompt = f"<|im_start|>system\nYou are a funny and smart AI monster. Answer in Hebrew.<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 11 |
|
| 12 |
payload = {
|
| 13 |
+
"inputs": prompt,
|
| 14 |
+
"parameters": {"max_new_tokens": 512, "temperature": 0.7}
|
| 15 |
}
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
response = requests.post(API_URL, json=payload, timeout=20)
|
| 19 |
|
| 20 |
+
# ืืืคืื ืืืฆื ืฉืืืืื ื ืืขื (ืฉืืืื 503)
|
| 21 |
if response.status_code == 503:
|
| 22 |
time.sleep(5)
|
| 23 |
+
response = requests.post(API_URL, json=payload, timeout=20)
|
| 24 |
|
| 25 |
result = response.json()
|
| 26 |
|
| 27 |
+
# ืืืืืฅ ืืชืฉืืื ืืืคืืจืื ืฉื Qwen
|
| 28 |
if isinstance(result, list) and len(result) > 0:
|
| 29 |
+
text = result[0].get('generated_text', "")
|
| 30 |
+
# ื ืืงืื ืืืงืกื ืืื ืืืฉืืืจ ืจืง ืืช ืืชืฉืืื ืฉื ื-AI
|
| 31 |
+
answer = text.split("<|im_start|>assistant\n")[-1].replace("<|im_end|>", "").strip()
|
| 32 |
+
return answer
|
| 33 |
+
return "ืืืคืืฆืช ืืืชืืื ื ืืืฉืืช... ื ืกื ืืฉืืื ืฉืื!"
|
| 34 |
except:
|
| 35 |
+
return "ืืฉ ืขืืืก ืขื ืืืืื ืืืคืืฆืชื ืืื, ื ืกื ืฉืื ืืขืื ืจืืข."
|
| 36 |
|
| 37 |
+
# ืืืฉืง ืืฆ'ืื
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
+
gr.Markdown(f"# ๐พ {next(iter(['Qwen 3.5 Monster Chat']))}")
|
| 40 |
gr.ChatInterface(fn=monster_chat)
|
| 41 |
|
|
|
|
| 42 |
demo.launch()
|