Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdd translation step with facebook/m2m100_418M for Chinese output
9 unmodified lines1011121314151617181920212223242526279 unmodified linesprint(f"HF_TOKEN loaded: {len(HF_TOKEN) if HF_TOKEN else 0} characters")try:client = InferenceClient(model="google/pegasus-xsum", token=HF_TOKEN)def generate_summary(text):for _ in range(3):try:response = client.summarization(text, max_length=50, min_length=10, num_beams=4)print(f"API Response: {response}")if hasattr(response, 'generated_text') and response.generated_text:return response.generated_textelif hasattr(response, 'summary_text') and response.summary_text:return response.summary_textelse:return "摘要生成失败,属性缺失。"except Exception as e:error_details = traceback.format_exc()print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")9 unmodified lines1011121314151617181920212223242526272829303132333435369 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",tgt_lang="zh",max_length=100)print(f"Translation API Response: {translated_response}")return translated_response if translated_response else "翻译失败,请重试。"except Exception as e:error_details = traceback.format_exc()print(f"尝试失败,错误类型: {type(e).__name__}, 错误详情: {str(e)}, 堆栈: {error_details}")
app.py+17-8