uumerrr684 commited on
Commit
9631de2
·
verified ·
1 Parent(s): 8770252

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -3,20 +3,13 @@ import requests
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,9 +21,6 @@ def summarize(text):
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,4 +49,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
59
  fn=summarize,
60
  inputs=input_txt,
61
  outputs=[output_txt, status]
62
- )
 
 
 
 
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
  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
  fn=summarize,
50
  inputs=input_txt,
51
  outputs=[output_txt, status]
52
+ )
53
+
54
+ if __name__ == "__main__":
55
+ app.launch(server_name="0.0.0.0", server_port=7860)