Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
import time
|
| 5 |
|
| 6 |
def monster_chat(message, history):
|
| 7 |
-
#
|
| 8 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 9 |
|
| 10 |
-
# ืื ืืืช ืืคืจืืืคื ืืฆืืจื ืฉืืืืื ืืืื ืฉืืื ืืฆ'ืื
|
| 11 |
payload = {
|
| 12 |
-
"inputs": f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are a funny
|
| 13 |
-
"parameters": {"max_new_tokens":
|
| 14 |
}
|
| 15 |
|
| 16 |
-
# ื ืืกืืื ืจืืฉืื ืืฉืืื ืืืืขื
|
| 17 |
try:
|
| 18 |
response = requests.post(API_URL, json=payload, timeout=15)
|
| 19 |
|
| 20 |
-
# ืื ืืืืื ืืืขืื ื, ื ืืื
|
| 21 |
if response.status_code == 503:
|
| 22 |
time.sleep(5)
|
| 23 |
response = requests.post(API_URL, json=payload, timeout=15)
|
|
@@ -25,17 +22,15 @@ def monster_chat(message, history):
|
|
| 25 |
result = response.json()
|
| 26 |
|
| 27 |
if isinstance(result, list) and len(result) > 0:
|
| 28 |
-
return result[0].get('generated_text', "
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
return "ืืืคืืฆืช ืื ืกื ืืืืื ืื ืืืจืช... ืชืฉืื ืฉืื!"
|
| 33 |
-
except Exception as e:
|
| 34 |
-
return "ืืฉ ืชืงืื ืืืืืืจ ืืืคืืฆืช, ื ืกื ืฉืื ืืขืื ืืื ืฉื ืืืช."
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
with gr.Blocks(
|
| 38 |
-
gr.
|
| 39 |
-
gr.ChatInterface(fn=monster_chat
|
| 40 |
|
|
|
|
| 41 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
def monster_chat(message, history):
|
| 6 |
+
# ืืืื Llama-3 ืืืฆืื
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 8 |
|
|
|
|
| 9 |
payload = {
|
| 10 |
+
"inputs": f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are a funny AI. Answer in Hebrew.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
|
| 11 |
+
"parameters": {"max_new_tokens": 150, "temperature": 0.7}
|
| 12 |
}
|
| 13 |
|
|
|
|
| 14 |
try:
|
| 15 |
response = requests.post(API_URL, json=payload, timeout=15)
|
| 16 |
|
| 17 |
+
# ืื ืืืืื ืืืขืื ื (503), ื ืืื ืงืฆืช
|
| 18 |
if response.status_code == 503:
|
| 19 |
time.sleep(5)
|
| 20 |
response = requests.post(API_URL, json=payload, timeout=15)
|
|
|
|
| 22 |
result = response.json()
|
| 23 |
|
| 24 |
if isinstance(result, list) and len(result) > 0:
|
| 25 |
+
return result[0].get('generated_text', "ืืืคืืฆืช ืืืืื ืืช ืืงืื!")
|
| 26 |
+
return "ืืืคืืฆืช ืืืฉืืช... ื ืกื ืืฉืืื ืฉืื."
|
| 27 |
+
except:
|
| 28 |
+
return "ืชืงืื ืืืืืืจ ืืืคืืฆืช."
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# ืืฆืืจืช ืืืืฉืง ืืฆืืจื ื ืงืืื ืืื ืคืจืืืจืื ืฉืืืจืื
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# ๐พ MONSTER CHAT")
|
| 33 |
+
gr.ChatInterface(fn=monster_chat)
|
| 34 |
|
| 35 |
+
# ืืขืืจื ื ืืช ื-theme ืืคื, ืืืืืง ืืื ืฉืืฉืืืื ืืืงืฉื
|
| 36 |
demo.launch()
|