Download app.py from Marty0618/hellochat: direct link, hf CLI and curl.
- Browser
- Download file 865 Bytes
-
https://huggingface.co/spaces/Marty0618/hellochat/resolve/main/app.py
- Command line
-
hf download hf://spaces/Marty0618/hellochat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Marty0618/hellochat/resolve/main/app.py
865 Bytes
| import gradio as gr | |
| from utils import format_chat_history, get_qwen_response | |
| def chat_with_qwen(message, history): | |
| """使用通义千问API进行对话""" | |
| # 格式化历史消息 | |
| messages = format_chat_history(history, message) | |
| # 调用通义千问API | |
| response = get_qwen_response(messages) | |
| if response['success']: | |
| return response['content'] | |
| else: | |
| return f"⚠️ {response['content']}" | |
| # 创建Gradio界面 | |
| demo = gr.ChatInterface( | |
| fn=chat_with_qwen, | |
| title="通义千问聊天机器人", | |
| description="这是一个使用DashScope API调用通义千问大模型的聊天机器人", | |
| examples=["你好,请介绍一下自己", "什么是人工智能?", "给我讲个故事"], | |
| theme="soft" | |
| ) | |
| # 启动应用 | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) |