Updated to plain request
Browse files
app.py
CHANGED
|
@@ -1,16 +1,27 @@
|
|
| 1 |
import os
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
|
|
|
|
| 5 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
+
import requests
|
| 3 |
+
import gradio as gr # Or whatever UI you use
|
| 4 |
|
| 5 |
+
# 1. Pull your secret token
|
| 6 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 7 |
|
| 8 |
+
# 2. Define the full URL to your private FastAPI endpoint
|
| 9 |
+
# Note: Use the direct .hf.space URL
|
| 10 |
+
API_URL = "https://rr19tech-plnb-demo.hf.space/"
|
| 11 |
|
| 12 |
+
def call_private_api(payload):
|
| 13 |
+
# Pass the token in the Authorization header
|
| 14 |
+
headers = {
|
| 15 |
+
"Authorization": f"Bearer {HF_TOKEN}",
|
| 16 |
+
"Content-Type": "application/json"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
response = requests.post(API_URL, json={"input": payload}, headers=headers)
|
| 20 |
+
|
| 21 |
+
if response.status_code == 200:
|
| 22 |
+
return response.json()
|
| 23 |
+
else:
|
| 24 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 25 |
|
| 26 |
+
# Simple UI to test it
|
| 27 |
+
gr.Interface(fn=call_private_api, inputs="text", outputs="json").launch()
|