Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,20 @@ import requests
|
|
| 3 |
import gradio as gr
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
load_dotenv()
|
|
|
|
| 7 |
|
| 8 |
def summarize(text):
|
| 9 |
"""Foolproof summarization with full error handling"""
|
| 10 |
try:
|
| 11 |
-
# 1. Verify token
|
| 12 |
token = os.getenv("HF_API_TOKEN")
|
|
|
|
|
|
|
|
|
|
| 13 |
if not token:
|
| 14 |
return "⚠️ Token missing: Set HF_API_TOKEN in Secrets", ""
|
| 15 |
|
|
@@ -21,6 +28,9 @@ def summarize(text):
|
|
| 21 |
timeout=30
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
# 3. Handle all response cases
|
| 25 |
if response.status_code == 200:
|
| 26 |
return response.json()[0].get("summary_text", "⚠️ Empty response"), "✅ Success"
|
|
@@ -49,6 +59,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 49 |
fn=summarize,
|
| 50 |
inputs=input_txt,
|
| 51 |
outputs=[output_txt, status]
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
app.launch()
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
+
# Debug: Check environment loading
|
| 7 |
+
print("=== ENVIRONMENT CHECK ===")
|
| 8 |
+
print("Environment variables:", list(os.environ.keys()))
|
| 9 |
load_dotenv()
|
| 10 |
+
print("Token exists in environment:", "HF_API_TOKEN" in os.environ)
|
| 11 |
|
| 12 |
def summarize(text):
|
| 13 |
"""Foolproof summarization with full error handling"""
|
| 14 |
try:
|
| 15 |
+
# 1. Verify token with debug info
|
| 16 |
token = os.getenv("HF_API_TOKEN")
|
| 17 |
+
print(f"Token loaded: {'Yes' if token else 'No'}") # Debug line
|
| 18 |
+
print(f"Token first 3 chars: {token[:3] if token else 'N/A'}...") # Safe debug
|
| 19 |
+
|
| 20 |
if not token:
|
| 21 |
return "⚠️ Token missing: Set HF_API_TOKEN in Secrets", ""
|
| 22 |
|
|
|
|
| 28 |
timeout=30
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Debug API response
|
| 32 |
+
print(f"API Status: {response.status_code}")
|
| 33 |
+
|
| 34 |
# 3. Handle all response cases
|
| 35 |
if response.status_code == 200:
|
| 36 |
return response.json()[0].get("summary_text", "⚠️ Empty response"), "✅ Success"
|
|
|
|
| 59 |
fn=summarize,
|
| 60 |
inputs=input_txt,
|
| 61 |
outputs=[output_txt, status]
|
| 62 |
+
)
|
|
|
|
|
|