jinv2 commited on
Commit
e31f82b
·
verified ·
1 Parent(s): 9b18ba6

Update app.py

Browse files

Remove hard-coded Token and use Secrets for security

Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -1,13 +1,16 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import time
 
 
 
 
4
 
5
  try:
6
- client = InferenceClient(model="sshleifer/distilbart-cnn-12-6")
7
  def generate_summary(text):
8
  for _ in range(3): # 重试3次
9
  try:
10
- # 尝试直接传递文本作为位置参数
11
  response = client.summarization(text)
12
  return response[0]['summary_text'] if response and 'summary_text' in response[0] else "摘要生成失败,请重试。"
13
  except Exception as e:
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import time
4
+ import os
5
+
6
+ # 从Secrets中读取HF_TOKEN
7
+ HF_TOKEN = os.getenv("HF_TOKEN")
8
 
9
  try:
10
+ client = InferenceClient(model="sshleifer/distilbart-cnn-12-6", token=HF_TOKEN)
11
  def generate_summary(text):
12
  for _ in range(3): # 重试3次
13
  try:
 
14
  response = client.summarization(text)
15
  return response[0]['summary_text'] if response and 'summary_text' in response[0] else "摘要生成失败,请重试。"
16
  except Exception as e: