|
|
|
|
|
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() |
|
|