Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdd traceback for detailed error logging
1 unmodified line2345678910111213141516171819208 unmodified lines2930313233343536371 unmodified linefrom huggingface_hub import InferenceClientimport timeimport os# 从Secrets中读取HF_TOKENHF_TOKEN = os.getenv("HF_TOKEN")try:client = InferenceClient(model="sshleifer/distilbart-cnn-12-6", token=HF_TOKEN)def generate_summary(text):for _ in range(3): # 重试3次try:response = client.summarization(text)return response[0]['summary_text'] if response and 'summary_text' in response[0] else "摘要生成失败,请重试。"except Exception as e:print(f"尝试失败: {e}")time.sleep(1)return "网络错误,请稍后重试。"interface = gr.Interface(8 unmodified linescss="body {background-color: #f0f0f0; font-family: Arial;}")except Exception as e:print(f"初始化错误: {e}")interface = gr.Interface(fn=lambda x: f"服务暂不可用,错误: {e}",inputs="text",outputs="text",title="MySmartSummary",1 unmodified line23456789101112131415161718192021222324258 unmodified lines343536373839404142431 unmodified linefrom huggingface_hub import InferenceClientimport timeimport osimport tracebackHF_TOKEN = os.getenv("HF_TOKEN")if not HF_TOKEN:raise ValueError("HF_TOKEN not found in Secrets. Please set it in Space settings.")print(f"HF_TOKEN loaded: {len(HF_TOKEN) if HF_TOKEN else 0} characters")try:client = InferenceClient(model="sshleifer/distilbart-cnn-12-6", token=HF_TOKEN)def generate_summary(text):for _ in range(3):try:response = client.summarization(text)print(f"API Response: {response}")return response[0]['summary_text'] if response and 'summary_text' in response[0] else "摘要生成失败,请重试。"except Exception as e:error_details = traceback.format_exc()print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")time.sleep(1)return "网络错误,请稍后重试。"interface = gr.Interface(8 unmodified linescss="body {background-color: #f0f0f0; font-family: Arial;}")except Exception as e:error_details = traceback.format_exc()print(f"初始化错误,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")interface = gr.Interface(fn=lambda x: f"服务暂不可用,错误: {str(e)}",inputs="text",outputs="text",title="MySmartSummary",
app.py+11-5