File size: 1,508 Bytes
c8dc18d
 
 
 
 
 
 
 
 
 
 
 
9132635
c8dc18d
 
 
 
 
 
 
 
 
 
 
 
07a55a7
c8dc18d
 
 
 
 
fb5fbee
c8dc18d
 
 
 
 
 
9132635
c8dc18d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- 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()