Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# 1. Retrieve the token from the environment
|
| 6 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
# 2. Function that calls the private Space
|
| 9 |
+
def call_private_space(user_input):
|
| 10 |
+
"""
|
| 11 |
+
Sends a POST request to the private Space's Gradio endpoint.
|
| 12 |
+
Adjust the URL or payload if your private Space uses something different.
|
| 13 |
+
"""
|
| 14 |
+
# The private Space's URL - note 'jtdearmon--rag_dal_budget' matches the subdomain pattern
|
| 15 |
+
private_url = "https://jtdearmon--rag_dal_budget.hf.space/run/predict"
|
| 16 |
+
|
| 17 |
+
headers = {
|
| 18 |
+
"Authorization": f"Bearer {HF_TOKEN}"
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Typical Gradio JSON payload for a single text input
|
| 22 |
+
payload = {
|
| 23 |
+
"data": [user_input]
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# Send request
|
| 27 |
+
response = requests.post(private_url, headers=headers, json=payload)
|
| 28 |
+
response_data = response.json()
|
| 29 |
+
|
| 30 |
+
# This depends on how your Gradio app in the private space returns output
|
| 31 |
+
# Usually it might be response_data["data"][0] if it returns one text output
|
| 32 |
+
result = response_data["data"][0]
|
| 33 |
+
|
| 34 |
+
return result
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# 3. Create a Gradio interface
|
| 38 |
+
interface = gr.Interface(
|
| 39 |
+
fn=call_private_space,
|
| 40 |
+
inputs="text",
|
| 41 |
+
outputs="text",
|
| 42 |
+
title="Public Demo for rag_dal_budget (Private)",
|
| 43 |
+
description="This public Space calls the private `rag_dal_budget` behind the scenes."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# 4. Launch the interface
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
interface.launch()
|