Update app.py
Browse files
app.py
CHANGED
|
@@ -60,7 +60,6 @@ def process_csv_files(
|
|
| 60 |
max_tokens,
|
| 61 |
temperature,
|
| 62 |
top_p,
|
| 63 |
-
request: gr.Request,
|
| 64 |
progress=gr.Progress()
|
| 65 |
):
|
| 66 |
"""
|
|
@@ -69,27 +68,12 @@ def process_csv_files(
|
|
| 69 |
if not files or len(files) == 0:
|
| 70 |
return "Please upload at least one CSV file.", None
|
| 71 |
|
| 72 |
-
#
|
| 73 |
import os
|
| 74 |
-
hf_token =
|
| 75 |
|
| 76 |
-
# Check if user is logged in via OAuth
|
| 77 |
-
if request:
|
| 78 |
-
# Try to get token from request headers or OAuth
|
| 79 |
-
try:
|
| 80 |
-
# In HF Spaces with OAuth, token is available in request
|
| 81 |
-
if hasattr(request, 'username') and request.username:
|
| 82 |
-
# User is logged in, try to get their token from environment
|
| 83 |
-
hf_token = os.environ.get("OAUTH_TOKEN") or os.environ.get("HF_TOKEN")
|
| 84 |
-
except:
|
| 85 |
-
pass
|
| 86 |
-
|
| 87 |
-
# Fallback to environment variables
|
| 88 |
if not hf_token:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if not hf_token:
|
| 92 |
-
return "❌ Error: Please login with your Hugging Face account using the button in the sidebar, or add your HF token as a Space Secret (HF_TOKEN).", None
|
| 93 |
|
| 94 |
client = InferenceClient(token=hf_token, model="meta-llama/Llama-3.3-70B-Instruct")
|
| 95 |
|
|
@@ -186,20 +170,17 @@ with gr.Blocks(title="Business Category Description Generator") as demo:
|
|
| 186 |
CLIP-ready visual descriptions for each category using AI.
|
| 187 |
|
| 188 |
**Instructions:**
|
| 189 |
-
1.
|
| 190 |
-
2.
|
| 191 |
-
3.
|
| 192 |
4. Click "Process Files" to generate descriptions
|
| 193 |
5. Download the output CSV files
|
| 194 |
|
| 195 |
-
*Note:
|
| 196 |
""")
|
| 197 |
|
| 198 |
with gr.Row():
|
| 199 |
with gr.Column(scale=1):
|
| 200 |
-
gr.Markdown("### 🔐 Authentication")
|
| 201 |
-
gr.LoginButton()
|
| 202 |
-
|
| 203 |
gr.Markdown("### ⚙️ Model Settings")
|
| 204 |
max_tokens = gr.Slider(
|
| 205 |
minimum=64,
|
|
|
|
| 60 |
max_tokens,
|
| 61 |
temperature,
|
| 62 |
top_p,
|
|
|
|
| 63 |
progress=gr.Progress()
|
| 64 |
):
|
| 65 |
"""
|
|
|
|
| 68 |
if not files or len(files) == 0:
|
| 69 |
return "Please upload at least one CSV file.", None
|
| 70 |
|
| 71 |
+
# Get HF token from environment variables
|
| 72 |
import os
|
| 73 |
+
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_TOKEN")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
if not hf_token:
|
| 76 |
+
return "❌ Error: HF_TOKEN not found. Please add your Hugging Face token as a Space Secret.\n\nGo to Space Settings → Secrets → Add 'HF_TOKEN'", None
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
client = InferenceClient(token=hf_token, model="meta-llama/Llama-3.3-70B-Instruct")
|
| 79 |
|
|
|
|
| 170 |
CLIP-ready visual descriptions for each category using AI.
|
| 171 |
|
| 172 |
**Instructions:**
|
| 173 |
+
1. Upload one or more CSV files
|
| 174 |
+
2. Specify the column name that contains the category keywords
|
| 175 |
+
3. Adjust model settings if needed (optional)
|
| 176 |
4. Click "Process Files" to generate descriptions
|
| 177 |
5. Download the output CSV files
|
| 178 |
|
| 179 |
+
*Note: Authentication is handled via HF_TOKEN secret configured in Space settings.*
|
| 180 |
""")
|
| 181 |
|
| 182 |
with gr.Row():
|
| 183 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
| 184 |
gr.Markdown("### ⚙️ Model Settings")
|
| 185 |
max_tokens = gr.Slider(
|
| 186 |
minimum=64,
|