leeoxiang commited on
Commit
4248a83
1 Parent(s): f42ec94
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +71 -0
  3. requirements.txt +8 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__/
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import os
4
+ import gradio as gr
5
+
6
+
7
+ from langchain.llms import OpenAI
8
+ from langchain.chat_models import ChatOpenAI
9
+ from langchain.chains import ConversationChain
10
+ from langchain.memory import ConversationBufferWindowMemory
11
+
12
+
13
+ llm = ChatOpenAI(temperature=0.7, max_tokens=2000, verbose=True)
14
+
15
+ prompt_template = """
16
+ 你是一个保险行业的专家,你可以根据聊天记录,以及相应的风格,针对输入改写出写出相应的输出。
17
+ 聊天记录:{chat_history}
18
+ 风格:{style}
19
+ 输入:{input}
20
+ 输出:
21
+ """
22
+
23
+ conversation_with_summary = ConversationChain(
24
+ llm=llm,
25
+ memory=ConversationBufferWindowMemory(k=3),
26
+ prompt=prompt_template,
27
+ verbose=True
28
+ )
29
+
30
+ conversation_with_summary.predict(input="Hi, what's up?")
31
+
32
+
33
+ title = """<h1 align="center">🔥 AI 文案助手🚀</h1>"""
34
+
35
+
36
+ STYLES = [
37
+ '正常',
38
+ '直白一点',
39
+ '简洁一点',
40
+ '幽默一点',
41
+ '碎碎念',
42
+ '比喻句',
43
+ '口语化'
44
+ ]
45
+
46
+
47
+ 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:
48
+
49
+ gr.HTML(title)
50
+
51
+ with gr.Row():
52
+ with gr.Column(scale=1):
53
+ with gr.Row():
54
+ emptyBtn = gr.Button(
55
+ "🧹 改写"
56
+ )
57
+ model_select_dropdown = gr.Dropdown(
58
+ label="选择风格", choices=STYLES, value=STYLES[0], interactive=True
59
+ )
60
+ with gr.Column(scale=3):
61
+ pass
62
+
63
+ with gr.Row():
64
+ input = gr.Textbox(label='输入', show_label=True,
65
+ lines=40, elem_id="input_text")
66
+ outtxt = gr.Textbox(label='输出', show_label=True,
67
+ lines=40, elem_id="output_text")
68
+
69
+
70
+ demo.queue(concurrency_count=20)
71
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ chromadb==0.3.21
2
+ gradio==3.24.1
3
+ gradio_client==0.0.8
4
+ huggingface-hub==0.13.4
5
+ langchain==0.0.134
6
+ llama-index==0.5.4
7
+ openai==0.27.2
8
+ tiktoken