Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
return "❌ HF_API_TOKEN is NOT set (None)"
|
| 8 |
-
elif token.strip() == "":
|
| 9 |
-
return "⚠️ HF_API_TOKEN is set but empty"
|
| 10 |
-
else:
|
| 11 |
-
masked_token = token[:4] + "..." + token[-4:]
|
| 12 |
-
return f"✅ HF_API_TOKEN is set: {masked_token}"
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
HF_API_TOKEN = os.getenv("HF_API_TOKEN")
|
| 6 |
+
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
|
| 7 |
+
headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def call_hf(prompt):
|
| 10 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
| 11 |
+
return f"Status: {response.status_code}, Response: {response.text}"
|
| 12 |
+
|
| 13 |
+
gr.Interface(call_hf, "text", "text").launch()
|