wintergw commited on
Commit
30e6ebc
·
verified ·
1 Parent(s): 17bd1ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -34
app.py CHANGED
@@ -1,34 +1,19 @@
1
- import streamlit as st
2
- import requests
3
- import os
4
-
5
- # Hugging Face API Token (stored in secrets)
6
- HF_TOKEN = os.getenv("HF_TOKEN")
7
-
8
- # Private Space API URL (ensure it's correct)
9
- PRIVATE_SPACE_URL = "https://wintergw-mywebsite-private.hf.space:7860/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}")
 
1
+ from huggingface_hub import hf_hub_download , snapshot_download
2
+ import pandas as pd
3
+ import importlib
4
+ # snapshot_downloading your private space
5
+ snapshot_download(
6
+ repo_id="wintergw/assignment_opt_gurobi",
7
+ repo_type="space",
8
+ cache_dir="private_space_cache"
9
+ )
10
+ # calling the app code
11
+ app = hf_hub_download(
12
+ repo_id="wintergw/assignment_opt_gurobi",
13
+ filename="app.py",
14
+ repo_type="space"
15
+ )
16
+ # executing the app file
17
+ spec_app = importlib.util.spec_from_file_location("*",app_path)
18
+ app = importlib.util.module_from_spec(spec_app)
19
+ spec_app.loader.exec_module(app)