Spaces:
Runtime error
Runtime error
Download app.py from shuanglei/articlePolisher: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/shuanglei/articlePolisher/resolve/main/app.py
- Command line
-
hf download hf://spaces/shuanglei/articlePolisher/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shuanglei/articlePolisher/resolve/main/app.py
1.51 kB
| # -*- coding: utf-8-*- | |
| import openai | |
| import gradio as gr | |
| import os | |
| #机器人女友 | |
| openai.api_key = os.environ.get("OPENAI_API_KEY") | |
| prompt= """ | |
| 我想让你充当一个文字润色工具。我会给你一些文字,你不需要修改文字表达的意思,只是做一些润色优化。做到以下功能: | |
| - 文章中可能存在语法、拼写或标点符号错误,需要进行修改和校正。 | |
| - 文章的句子结构可能不够清晰、明确,需要进行适当调整和简化。 | |
| - 文章的段落结构可能不够紧凑、连贯,需要进行合并或拆分。 | |
| - 文章的用词可能不够准确、恰当,需要进行替换或修改。 | |
| - 文章的格式可能不够规范、整洁,需要进行调整和统一。 | |
| """ | |
| messages = [ | |
| {"role": "system", "content": prompt}, | |
| ] | |
| def chatbot(input): | |
| if input: | |
| global messages | |
| messages.append({"role": "user", "content": input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages = [{"role": "system", "content": prompt}] | |
| return reply | |
| inputs = gr.inputs.Textbox(lines=7, label="文字润色机") | |
| outputs = gr.outputs.Textbox(label="文字润色机") | |
| app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人", | |
| description="你面前的是一个文字润色机器人,他会给你对应修改后的文字", | |
| theme="compact") | |
| app.launch() |