Spaces:
Runtime error
Runtime error
asuayu commited on
Commit ·
c8dc18d
1
Parent(s): ad6003a
add
Browse files- app.py +40 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8-*-
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
+
#机器人女友
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
prompt= """
|
| 13 |
+
我想让你充当一个文字润色工具。做到以下功能:
|
| 14 |
+
- 文章中可能存在语法、拼写或标点符号错误,需要进行修改和校正。
|
| 15 |
+
- 文章的句子结构可能不够清晰、明确,需要进行适当调整和简化。
|
| 16 |
+
- 文章的段落结构可能不够紧凑、连贯,需要进行合并或拆分。
|
| 17 |
+
- 文章的用词可能不够准确、恰当,需要进行替换或修改。
|
| 18 |
+
- 文章的格式可能不够规范、整洁,需要进行调整和统一。
|
| 19 |
+
"""
|
| 20 |
+
messages = [
|
| 21 |
+
{"role": "system", "content": prompt},
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
def chatbot(input):
|
| 25 |
+
if input:
|
| 26 |
+
messages.append({"role": "user", "content": input})
|
| 27 |
+
chat = openai.ChatCompletion.create(
|
| 28 |
+
model="gpt-3.5-turbo", messages=messages
|
| 29 |
+
)
|
| 30 |
+
reply = chat.choices[0].message.content
|
| 31 |
+
messages.append({"role": "assistant", "content": reply})
|
| 32 |
+
return reply
|
| 33 |
+
|
| 34 |
+
inputs = gr.inputs.Textbox(lines=7, label="文字润色机")
|
| 35 |
+
outputs = gr.outputs.Textbox(label="文字润色机")
|
| 36 |
+
|
| 37 |
+
app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人",
|
| 38 |
+
description="你面前的是一个文章润色机器人,他会给你对应修改后的文字",
|
| 39 |
+
theme="compact")
|
| 40 |
+
app.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai==0.27.0
|