Spaces:
Runtime error
Runtime error
Update app.py
Browse filesSwitch to facebook/bart-large-cnn due to 503 error
9 unmodified lines101112131415161718192021222324252627286 unmodified lines353637383940419 unmodified linesprint(f"HF_TOKEN loaded: {len(HF_TOKEN) if HF_TOKEN else 0} characters")try:summary_client = InferenceClient(model="google/pegasus-xsum", token=HF_TOKEN)translation_client = InferenceClient(model="facebook/m2m100_418M", token=HF_TOKEN)def generate_summary(text):for _ in range(3):try:# 首先生成英文摘要response = summary_client.summarization(text)print(f"Summary API Response: {response}")summary_text = response.generated_text if hasattr(response, 'generated_text') and response.generated_text else response.summary_text if hasattr(response, 'summary_text') and response.summary_text else Noneif not summary_text:return "摘要生成失败,属性缺失。"# 将英文摘要翻译为中文translated_response = translation_client.text_generation(summary_text,src_lang="en",6 unmodified lineserror_details = traceback.format_exc()print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")time.sleep(1)return "网络错误,请稍后重试。"interface = gr.Interface(fn=generate_summary,inputs=gr.Textbox(lines=5, placeholder="输入文档内容..."),9 unmodified lines101112131415161718192021222324256 unmodified lines32333435363738399 unmodified linesprint(f"HF_TOKEN loaded: {len(HF_TOKEN) if HF_TOKEN else 0} characters")try:summary_client = InferenceClient(model="facebook/bart-large-cnn", token=HF_TOKEN)translation_client = InferenceClient(model="facebook/m2m100_418M", token=HF_TOKEN)def generate_summary(text):for _ in range(3):try:response = summary_client.summarization(text)print(f"Summary API Response: {response}")summary_text = response.generated_text if hasattr(response, 'generated_text') and response.generated_text else response.summary_text if hasattr(response, 'summary_text') and response.summary_text else Noneif not summary_text:return "摘要生成失败,属性缺失。"translated_response = translation_client.text_generation(summary_text,src_lang="en",6 unmodified lineserror_details = traceback.format_exc()print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")time.sleep(1)return f"网络错误,请稍后重试。错误详情:{str(e)}"return "网络错误,请稍后重试(重试次数已达上限)。"interface = gr.Interface(fn=generate_summary,inputs=gr.Textbox(lines=5, placeholder="输入文档内容..."),
app.py+3-5