Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Hugging Face API Token (stored as a secret in the public Space)
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
# Private Space API URL (replace with your actual username and private Space name)
|
| 9 |
+
PRIVATE_SPACE_URL = "https://YOUR_USERNAME-YOUR_PRIVATE_SPACE.hf.space/run"
|
| 10 |
+
|
| 11 |
+
st.title("🔗 Connect to Private Hugging Face Space")
|
| 12 |
+
st.write("This public app calls the private Streamlit app through an API.")
|
| 13 |
+
|
| 14 |
+
# Upload a file to send to the private Space
|
| 15 |
+
uploaded_file = st.file_uploader("📂 Upload your Excel File", type=["xlsx"])
|
| 16 |
+
|
| 17 |
+
if uploaded_file:
|
| 18 |
+
st.success("✅ File uploaded. Sending to private Space...")
|
| 19 |
+
|
| 20 |
+
# Send file to the private Space API
|
| 21 |
+
files = {"file": uploaded_file.getvalue()}
|
| 22 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
response = requests.post(PRIVATE_SPACE_URL, files=files, headers=headers)
|
| 26 |
+
|
| 27 |
+
if response.status_code == 200:
|
| 28 |
+
st.success("✅ Private Space processed the file successfully!")
|
| 29 |
+
st.write(response.json()) # Display results
|
| 30 |
+
else:
|
| 31 |
+
st.error(f"❌ Error: {response.status_code} - {response.text}")
|
| 32 |
+
|
| 33 |
+
except requests.exceptions.RequestException as e:
|
| 34 |
+
st.error(f"🚨 Request failed: {e}")
|