File size: 1,822 Bytes
4248a83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72


import os
import gradio as gr


from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferWindowMemory


llm = ChatOpenAI(temperature=0.7, max_tokens=2000, verbose=True)

prompt_template = """
你是一个保险行业的专家,你可以根据聊天记录,以及相应的风格,针对输入改写出写出相应的输出。
聊天记录:{chat_history}
风格:{style}
输入:{input}
输出:
"""

conversation_with_summary = ConversationChain(
    llm=llm,
    memory=ConversationBufferWindowMemory(k=3),
    prompt=prompt_template,
    verbose=True
)

conversation_with_summary.predict(input="Hi, what's up?")


title = """<h1 align="center">🔥 AI 文案助手🚀</h1>"""


STYLES = [
    '正常',
    '直白一点',
    '简洁一点',
    '幽默一点',
    '碎碎念',
    '比喻句',
    '口语化'
]


with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm, radius_size=gr.themes.sizes.radius_sm, text_size=gr.themes.sizes.text_sm)) as demo:

    gr.HTML(title)

    with gr.Row():
        with gr.Column(scale=1):
            with gr.Row():
                emptyBtn = gr.Button(
                    "🧹 改写"
                )
                model_select_dropdown = gr.Dropdown(
                    label="选择风格", choices=STYLES, value=STYLES[0], interactive=True
                )
        with gr.Column(scale=3):
            pass

    with gr.Row():
        input = gr.Textbox(label='输入', show_label=True,
                           lines=40, elem_id="input_text")
        outtxt = gr.Textbox(label='输出', show_label=True,
                            lines=40, elem_id="output_text")


demo.queue(concurrency_count=20)
demo.launch()