rr19tech commited on
Commit
69a9366
·
verified ·
1 Parent(s): 2b709fe

Updated to plain request

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -1,16 +1,27 @@
1
  import os
2
- import gradio as gr
3
- from gradio_client import Client
4
 
 
5
  HF_TOKEN = os.environ.get("HF_TOKEN")
6
 
7
- # Connect specifically via the Client
8
- client = Client("rr19tech/PLNB-Demo", token=HF_TOKEN)
 
9
 
10
- def predict(text):
11
- # This calls the private Space's API directly from the server
12
- result = client.predict(text, api_name="/predict")
13
- return result
 
 
 
 
 
 
 
 
 
14
 
15
- demo = gr.Interface(fn=predict, inputs="text", outputs="text")
16
- demo.launch()
 
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()