Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,12 @@ import requests
|
|
5 |
# --------------------------
|
6 |
# Configuration
|
7 |
# --------------------------
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
headers = {
|
12 |
"Authorization": f"Bearer {HF_TOKEN}",
|
@@ -32,6 +36,8 @@ def generate_text(prompt, max_length=150, temperature=0.7):
|
|
32 |
response = requests.post(HF_ENDPOINT_URL, headers=headers, json=payload)
|
33 |
if response.status_code == 200:
|
34 |
return response.json()[0]["generated_text"]
|
|
|
|
|
35 |
else:
|
36 |
return f"❌ Error {response.status_code}: {response.text}"
|
37 |
except Exception as e:
|
@@ -40,9 +46,9 @@ def generate_text(prompt, max_length=150, temperature=0.7):
|
|
40 |
# --------------------------
|
41 |
# Gradio UI
|
42 |
# --------------------------
|
43 |
-
with gr.Blocks(title="Burmese-GPT-v3 (Endpoint)") as demo:
|
44 |
-
gr.Markdown("##
|
45 |
-
gr.Markdown("
|
46 |
|
47 |
with gr.Row():
|
48 |
with gr.Column(scale=3):
|
@@ -54,7 +60,7 @@ with gr.Blocks(title="Burmese-GPT-v3 (Endpoint)") as demo:
|
|
54 |
with gr.Column(scale=1):
|
55 |
max_length = gr.Slider(
|
56 |
minimum=50,
|
57 |
-
maximum=
|
58 |
value=150,
|
59 |
step=10,
|
60 |
label="Max New Tokens"
|
@@ -77,9 +83,13 @@ with gr.Blocks(title="Burmese-GPT-v3 (Endpoint)") as demo:
|
|
77 |
)
|
78 |
|
79 |
with gr.Accordion("📌 Example Prompts", open=False):
|
|
|
80 |
examples = [
|
81 |
["မင်္ဂလာပါ။ ကျွန်တော်က ကိုအောင်ပါ။ ရန်ကုန်မှာနေတယ်။ ဆရာလုပ်ပါတယ်။", 150, 0.7],
|
82 |
-
["မြန်မာနိုင်ငံမှာ
|
|
|
|
|
|
|
83 |
]
|
84 |
for idx, ex in enumerate(examples):
|
85 |
example_btn = gr.Button(f"Example {idx+1}")
|
@@ -93,7 +103,13 @@ with gr.Blocks(title="Burmese-GPT-v3 (Endpoint)") as demo:
|
|
93 |
outputs=output
|
94 |
)
|
95 |
|
96 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
# --------------------------
|
99 |
# Launch
|
|
|
5 |
# --------------------------
|
6 |
# Configuration
|
7 |
# --------------------------
|
8 |
+
|
9 |
+
# ✅ Your actual Inference Endpoint URL
|
10 |
+
HF_ENDPOINT_URL = "https://dqptyla9qxd15452.us-east-1.aws.endpoints.huggingface.cloud"
|
11 |
+
|
12 |
+
# ✅ Your token securely accessed via Hugging Face Secrets
|
13 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
14 |
|
15 |
headers = {
|
16 |
"Authorization": f"Bearer {HF_TOKEN}",
|
|
|
36 |
response = requests.post(HF_ENDPOINT_URL, headers=headers, json=payload)
|
37 |
if response.status_code == 200:
|
38 |
return response.json()[0]["generated_text"]
|
39 |
+
elif response.status_code == 404:
|
40 |
+
return "❌ Endpoint not found. Please check your HF_ENDPOINT_URL."
|
41 |
else:
|
42 |
return f"❌ Error {response.status_code}: {response.text}"
|
43 |
except Exception as e:
|
|
|
46 |
# --------------------------
|
47 |
# Gradio UI
|
48 |
# --------------------------
|
49 |
+
with gr.Blocks(title="Burmese-GPT-v3 (Hosted Inference Endpoint)") as demo:
|
50 |
+
gr.Markdown("## 🧠 Burmese GPT-3 Text Generator")
|
51 |
+
gr.Markdown("This app connects to a Hugging Face Inference Endpoint to generate Burmese language text.\n\nJust enter a prompt in Burmese, adjust settings, and hit 'Generate Text'!")
|
52 |
|
53 |
with gr.Row():
|
54 |
with gr.Column(scale=3):
|
|
|
60 |
with gr.Column(scale=1):
|
61 |
max_length = gr.Slider(
|
62 |
minimum=50,
|
63 |
+
maximum=500,
|
64 |
value=150,
|
65 |
step=10,
|
66 |
label="Max New Tokens"
|
|
|
83 |
)
|
84 |
|
85 |
with gr.Accordion("📌 Example Prompts", open=False):
|
86 |
+
gr.Markdown("Click on a prompt below to try it out:")
|
87 |
examples = [
|
88 |
["မင်္ဂလာပါ။ ကျွန်တော်က ကိုအောင်ပါ။ ရန်ကုန်မှာနေတယ်။ ဆရာလုပ်ပါတယ်။", 150, 0.7],
|
89 |
+
["မြန်မာနိုင်ငံမှာ မိုးရာသီမှာ မိုးဘယ်လောက်ကျလဲ။", 150, 0.6],
|
90 |
+
["အောင်မြင်တဲ့ကျောင်းသူတစ်ယောက်ဖြစ်ဖို့ ဘယ်လိုလေ့ကျင့်ရမလဲ။", 200, 0.8],
|
91 |
+
["မြန်မာ့ယဉ်ကျေးမှုအကြောင်း ပြောပြပါ။", 150, 0.7],
|
92 |
+
["သင်တောင်ကြီးသွားဖူးလား။ ဘယ်မှာသွားဖူးလဲ။", 150, 0.6]
|
93 |
]
|
94 |
for idx, ex in enumerate(examples):
|
95 |
example_btn = gr.Button(f"Example {idx+1}")
|
|
|
103 |
outputs=output
|
104 |
)
|
105 |
|
106 |
+
gr.Markdown("""
|
107 |
+
---
|
108 |
+
### ℹ️ Troubleshooting
|
109 |
+
- If the app says "❌ Endpoint not found", double-check your `HF_ENDPOINT_URL`.
|
110 |
+
- If the model takes a few seconds to respond, it's just warming up from idle.
|
111 |
+
- Ensure your Hugging Face token is added as `HF_TOKEN` under **Settings → Secrets**.
|
112 |
+
""")
|
113 |
|
114 |
# --------------------------
|
115 |
# Launch
|