Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -48,11 +48,12 @@ FREE_MODELS = [
|
|
| 48 |
import time
|
| 49 |
|
| 50 |
def analyze_narrative(api_key, text, model_name, progress=gr.Progress()):
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 53 |
return
|
| 54 |
-
|
| 55 |
-
api_key = api_key.strip()
|
| 56 |
|
| 57 |
if not text.strip():
|
| 58 |
yield "⚠️ Error: Please enter some text to analyze."
|
|
@@ -63,7 +64,7 @@ def analyze_narrative(api_key, text, model_name, progress=gr.Progress()):
|
|
| 63 |
progress(0.1, desc="Connecting to Hugging Face...")
|
| 64 |
|
| 65 |
# Initialize the client
|
| 66 |
-
client = InferenceClient(token=
|
| 67 |
|
| 68 |
measure_message = [
|
| 69 |
{"role": "system", "content": SYSTEM_INSTRUCTION},
|
|
@@ -115,10 +116,10 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Policy Narrative Analyst (HF Editi
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column(scale=1):
|
| 117 |
api_key_input = gr.Textbox(
|
| 118 |
-
label="Hugging Face Token",
|
| 119 |
type="password",
|
| 120 |
-
placeholder="
|
| 121 |
-
info="
|
| 122 |
)
|
| 123 |
|
| 124 |
model_selector = gr.Dropdown(
|
|
|
|
| 48 |
import time
|
| 49 |
|
| 50 |
def analyze_narrative(api_key, text, model_name, progress=gr.Progress()):
|
| 51 |
+
# Prefer user input, fallback to environment variable
|
| 52 |
+
token_to_use = api_key.strip() if api_key else os.getenv("HF_TOKEN")
|
| 53 |
+
|
| 54 |
+
if not token_to_use:
|
| 55 |
+
yield "⚠️ Error: Please provide a Hugging Face Token (or set HF_TOKEN env var)."
|
| 56 |
return
|
|
|
|
|
|
|
| 57 |
|
| 58 |
if not text.strip():
|
| 59 |
yield "⚠️ Error: Please enter some text to analyze."
|
|
|
|
| 64 |
progress(0.1, desc="Connecting to Hugging Face...")
|
| 65 |
|
| 66 |
# Initialize the client
|
| 67 |
+
client = InferenceClient(token=token_to_use)
|
| 68 |
|
| 69 |
measure_message = [
|
| 70 |
{"role": "system", "content": SYSTEM_INSTRUCTION},
|
|
|
|
| 116 |
with gr.Row():
|
| 117 |
with gr.Column(scale=1):
|
| 118 |
api_key_input = gr.Textbox(
|
| 119 |
+
label="Hugging Face Token (Optional)",
|
| 120 |
type="password",
|
| 121 |
+
placeholder="Leave blank if HF_TOKEN is set in Secrets",
|
| 122 |
+
info="If using HF Spaces, add 'HF_TOKEN' to Settings -> Secrets."
|
| 123 |
)
|
| 124 |
|
| 125 |
model_selector = gr.Dropdown(
|