zxsipola123456 commited on
Commit
f9cf012
·
verified ·
1 Parent(s): f0931b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +152 -153
app.py CHANGED
@@ -207,7 +207,8 @@ def reload_model(choice):
207
  pass
208
 
209
 
210
- with gr.Blocks(title="RecurrentGPT", css="footer {visibility: hidden}", theme="default") as demo:
 
211
  if "en" == lang_opt:
212
  gr.Markdown(
213
  """
@@ -221,158 +222,156 @@ with gr.Blocks(title="RecurrentGPT", css="footer {visibility: hidden}", theme="d
221
  可以根据题目和简介自动续写文章
222
  也可以手动选择剧情走向进行续写
223
  """)
224
-
225
- with gr.Tab("Auto-Generation"):
226
- with gr.Row():
227
- with gr.Column():
228
- with gr.Row():
229
- with gr.Column(scale=1, min_width=200):
230
- novel_type = gr.Textbox(
231
- label="Novel Type", placeholder="e.g. science fiction") if "en" == lang_opt else gr.Textbox(
232
- label="请输入文本", placeholder="可以自己填写或者从EXamples中选择一个填入")
233
- with gr.Column(scale=2, min_width=400):
234
- description = gr.Textbox(
235
- label="Description") if "en" == lang_opt else gr.Textbox(label="剧情简介(非必选项)")
236
- btn_init = gr.Button(
237
- "Init Novel Generation", variant="primary") if "en" == lang_opt else gr.Button(
238
- "点击开始运行", variant="primary")
239
- if "en" == lang_opt:
240
- gr.Examples(["Science Fiction", "Romance", "Mystery", "Fantasy",
241
- "Historical", "Horror", "Thriller", "Western", "Young Adult", ], inputs=[novel_type])
242
- elif lang_opt in ["zh1", "zh2"]:
243
- gr.Examples(["科幻故事", "青春伤痛文学", "爱到死去活来", "搞笑",
244
- "幽默", "鬼故事", "喜剧", "童话", "魔法世界", ], inputs=[novel_type])
245
-
246
- written_paras = gr.Textbox(
247
- label="Written Paragraphs (editable)", max_lines=21, lines=21) if "en" == lang_opt else gr.Textbox(
248
- label="文章内容", max_lines=21, lines=21)
249
-
250
- with gr.Column():
251
- if "en" == lang_opt:
252
- gr.Markdown("### Memory Module\n")
253
- elif lang_opt in ["zh1", "zh2"]:
254
- gr.Markdown("### 剧情模型\n")
255
-
256
- short_memory = gr.Textbox(
257
- label="Short-Term Memory (editable)", max_lines=3, lines=3) if "en" == lang_opt else gr.Textbox(
258
- label="短期记忆 (可编辑)", max_lines=3, lines=3)
259
- long_memory = gr.Textbox(
260
- label="Long-Term Memory (editable)", max_lines=6, lines=6) if "en" == lang_opt else gr.Textbox(
261
- label="长期记忆 (可编辑)", max_lines=6, lines=6)
262
-
263
- if "en" == lang_opt:
264
- gr.Markdown("### Instruction Module\n")
265
- elif lang_opt in ["zh1", "zh2"]:
266
- gr.Markdown("### 选项模型\n")
267
-
268
- with gr.Row():
269
- instruction1 = gr.Textbox(
270
- label="Instruction 1 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
271
- label="指令1(可编辑)", max_lines=4, lines=4)
272
- instruction2 = gr.Textbox(
273
- label="Instruction 2 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
274
- label="指令2(可编辑)", max_lines=4, lines=4)
275
- instruction3 = gr.Textbox(
276
- label="Instruction 3 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
277
- label="指令3(可编辑)", max_lines=4, lines=4)
278
- selected_plan = gr.Textbox(
279
- label="Revised Instruction (from last step)", max_lines=2, lines=2) if "en" == lang_opt else gr.Textbox(
280
- label="选项说明 (来自上一步)", max_lines=2, lines=2)
281
-
282
- btn_step = gr.Button("Next Step", variant="primary") if "en" == lang_opt else gr.Button(
283
- "下一步", variant="primary")
284
-
285
- btn_init.click(init, inputs=[novel_type, description], outputs=[
286
- short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
287
- btn_step.click(step, inputs=[short_memory, long_memory, instruction1, instruction2, instruction3, written_paras], outputs=[
288
- short_memory, long_memory, written_paras, selected_plan, instruction1, instruction2, instruction3])
289
-
290
- with gr.Tab("Human-in-the-Loop"):
291
- with gr.Row():
292
- with gr.Column():
293
- with gr.Row():
294
- with gr.Column(scale=1, min_width=200):
295
- novel_type = gr.Textbox(
296
- label="Novel Type", placeholder="e.g. science fiction") if "en" == lang_opt else gr.Textbox(
297
- label="请输入文本", placeholder="可以自己填写或者从EXamples中选择一个填入")
298
- with gr.Column(scale=2, min_width=400):
299
- description = gr.Textbox(
300
- label="Description") if "en" == lang_opt else gr.Textbox(label="剧情简介(非必选项)")
301
- btn_init = gr.Button(
302
- "Init Novel Generation", variant="primary") if "en" == lang_opt else gr.Button(
303
- "点击开始运行", variant="primary")
304
-
305
- if "en" == lang_opt:
306
- gr.Examples(["Science Fiction", "Romance", "Mystery", "Fantasy",
307
- "Historical", "Horror", "Thriller", "Western", "Young Adult", ], inputs=[novel_type])
308
- elif lang_opt in ["zh1", "zh2"]:
309
- gr.Examples(["科幻小说", "爱情小说", "推理小说", "奇幻小说",
310
- "玄幻小说", "恐怖", "悬疑", "惊悚", "武侠小说", ], inputs=[novel_type])
311
-
312
- written_paras = gr.Textbox(
313
- label="Written Paragraphs (editable)", max_lines=23, lines=23) if "en" == lang_opt else gr.Textbox(
314
- label="文章内容 (可编辑)", max_lines=23, lines=23)
315
-
316
- with gr.Column():
317
- if "en" == lang_opt:
318
- gr.Markdown("### Memory Module\n")
319
- elif lang_opt in ["zh1", "zh2"]:
320
- gr.Markdown("### 剧情模型\n")
321
-
322
- short_memory = gr.Textbox(
323
- label="Short-Term Memory (editable)", max_lines=3, lines=3) if "en" == lang_opt else gr.Textbox(
324
- label="短期记忆 (可编辑)", max_lines=3, lines=3)
325
- long_memory = gr.Textbox(
326
- label="Long-Term Memory (editable)", max_lines=6, lines=6) if "en" == lang_opt else gr.Textbox(
327
- label="长期记忆 (可编辑)", max_lines=6, lines=6)
328
-
329
- if "en" == lang_opt:
330
- gr.Markdown("### Instruction Module\n")
331
- elif lang_opt in ["zh1", "zh2"]:
332
- gr.Markdown("### 选项模型\n")
333
-
334
- with gr.Row():
335
- instruction1 = gr.Textbox(
336
- label="Instruction 1", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
337
- label="指令1", max_lines=3, lines=3, interactive=False)
338
- instruction2 = gr.Textbox(
339
- label="Instruction 2", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
340
- label="指令2", max_lines=3, lines=3, interactive=False)
341
- instruction3 = gr.Textbox(
342
- label="Instruction 3", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
343
- label="指令3", max_lines=3, lines=3, interactive=False)
344
- with gr.Row():
345
- with gr.Column(scale=1, min_width=100):
346
- selected_plan = gr.Radio(
347
- ["Instruction 1", "Instruction 2", "Instruction 3"], label="Instruction Selection",) if "en" == lang_opt else gr.Radio(["指令 1", "指令 2", "指令 3"], label="指令 选择",)
348
- with gr.Column(scale=3, min_width=300):
349
- selected_instruction = gr.Textbox(
350
- label="Selected Instruction (editable)", max_lines=5, lines=5) if "en" == lang_opt else gr.Textbox(
351
- label="在上一步骤中被选择的 (可编辑)", max_lines=5, lines=5)
352
-
353
- btn_step = gr.Button("Next Step", variant="primary") if "en" == lang_opt else gr.Button(
354
- "下一步", variant="primary")
355
-
356
- btn_init.click(init, inputs=[novel_type, description], outputs=[
357
- short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
358
- btn_step.click(controled_step, inputs=[short_memory, long_memory, selected_instruction, written_paras], outputs=[
359
- short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
360
- selected_plan.select(on_select, inputs=[
361
- instruction1, instruction2, instruction3], outputs=[selected_instruction])
362
-
363
- with gr.Tab("Model-Config"):
364
- model_opt_radio = gr.Radio(["OpenAI", "ChatGLM-6B", "Vicuna-7B"], value="OpenAI", label="model",
365
- info="select language you preferred. Default is English.",
366
- interactive=True
367
- )
368
-
369
- reload_button = gr.Button("Reload/重新加载")
370
- reload_button.click(reload_model, show_progress=True,
371
- inputs=[model_opt_radio],
372
- outputs=[novel_type])
373
-
374
- demo.queue(concurrency_count=1)
375
 
376
  if __name__ == "__main__":
377
  demo.launch(show_error=True, show_api=False)
378
-
 
207
  pass
208
 
209
 
210
+
211
+ with gr.Blocks(title="小说GPT", css="footer {visibility: hidden}", theme="default") as demo:
212
  if "en" == lang_opt:
213
  gr.Markdown(
214
  """
 
222
  可以根据题目和简介自动续写文章
223
  也可以手动选择剧情走向进行续写
224
  """)
225
+ with gr.Tab("Auto-Generation"):
226
+ with gr.Row():
227
+ with gr.Column():
228
+ with gr.Row():
229
+ with gr.Column(scale=1, min_width=200):
230
+ novel_type = gr.Textbox(
231
+ label="Novel Type", placeholder="e.g. science fiction") if "en" == lang_opt else gr.Textbox(
232
+ label="请输入文本", placeholder="可以自己填写或者从EXamples中选择一个填入")
233
+ with gr.Column(scale=2, min_width=400):
234
+ description = gr.Textbox(
235
+ label="Description") if "en" == lang_opt else gr.Textbox(label="剧情简介(非必选项)")
236
+ btn_init = gr.Button(
237
+ "Init Novel Generation", variant="primary") if "en" == lang_opt else gr.Button(
238
+ "点击开始运行", variant="primary")
239
+ if "en" == lang_opt:
240
+ gr.Examples(["Science Fiction", "Romance", "Mystery", "Fantasy",
241
+ "Historical", "Horror", "Thriller", "Western", "Young Adult", ], inputs=[novel_type])
242
+ elif lang_opt in ["zh1", "zh2"]:
243
+ gr.Examples(["科幻故事", "青春伤痛文学", "爱到死去活来", "搞笑",
244
+ "幽默", "鬼故事", "喜剧", "童话", "魔法世界", ], inputs=[novel_type])
245
+
246
+ written_paras = gr.Textbox(
247
+ label="Written Paragraphs (editable)", max_lines=21, lines=21) if "en" == lang_opt else gr.Textbox(
248
+ label="文章内容", max_lines=21, lines=21)
249
+
250
+ with gr.Column():
251
+ if "en" == lang_opt:
252
+ gr.Markdown("### Memory Module\n")
253
+ elif lang_opt in ["zh1", "zh2"]:
254
+ gr.Markdown("### 剧情模型\n")
255
+
256
+ short_memory = gr.Textbox(
257
+ label="Short-Term Memory (editable)", max_lines=3, lines=3) if "en" == lang_opt else gr.Textbox(
258
+ label="短期记忆 (可编辑)", max_lines=3, lines=3)
259
+ long_memory = gr.Textbox(
260
+ label="Long-Term Memory (editable)", max_lines=6, lines=6) if "en" == lang_opt else gr.Textbox(
261
+ label="长期记忆 (可编辑)", max_lines=6, lines=6)
262
+
263
+ if "en" == lang_opt:
264
+ gr.Markdown("### Instruction Module\n")
265
+ elif lang_opt in ["zh1", "zh2"]:
266
+ gr.Markdown("### 选项模型\n")
267
+
268
+ with gr.Row():
269
+ instruction1 = gr.Textbox(
270
+ label="Instruction 1 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
271
+ label="指令1(可编辑)", max_lines=4, lines=4)
272
+ instruction2 = gr.Textbox(
273
+ label="Instruction 2 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
274
+ label="指令2(可编辑)", max_lines=4, lines=4)
275
+ instruction3 = gr.Textbox(
276
+ label="Instruction 3 (editable)", max_lines=4, lines=4) if "en" == lang_opt else gr.Textbox(
277
+ label="指令3(可编辑)", max_lines=4, lines=4)
278
+ selected_plan = gr.Textbox(
279
+ label="Revised Instruction (from last step)", max_lines=2, lines=2) if "en" == lang_opt else gr.Textbox(
280
+ label="选项说明 (来自上一步)", max_lines=2, lines=2)
281
+
282
+ btn_step = gr.Button("Next Step", variant="primary") if "en" == lang_opt else gr.Button(
283
+ "下一步", variant="primary")
284
+
285
+ btn_init.click(init, inputs=[novel_type, description], outputs=[
286
+ short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
287
+ btn_step.click(step, inputs=[short_memory, long_memory, instruction1, instruction2, instruction3, written_paras], outputs=[
288
+ short_memory, long_memory, written_paras, selected_plan, instruction1, instruction2, instruction3])
289
+
290
+ with gr.Tab("Human-in-the-Loop"):
291
+ with gr.Row():
292
+ with gr.Column():
293
+ with gr.Row():
294
+ with gr.Column(scale=1, min_width=200):
295
+ novel_type = gr.Textbox(
296
+ label="Novel Type", placeholder="e.g. science fiction") if "en" == lang_opt else gr.Textbox(
297
+ label="请输入文本", placeholder="可以自己填写或者从EXamples中选择一个填入")
298
+ with gr.Column(scale=2, min_width=400):
299
+ description = gr.Textbox(
300
+ label="Description") if "en" == lang_opt else gr.Textbox(label="剧情简介(非必选项)")
301
+ btn_init = gr.Button(
302
+ "Init Novel Generation", variant="primary") if "en" == lang_opt else gr.Button(
303
+ "点击开始运行", variant="primary")
304
+
305
+ if "en" == lang_opt:
306
+ gr.Examples(["Science Fiction", "Romance", "Mystery", "Fantasy",
307
+ "Historical", "Horror", "Thriller", "Western", "Young Adult", ], inputs=[novel_type])
308
+ elif lang_opt in ["zh1", "zh2"]:
309
+ gr.Examples(["科幻小说", "爱情小说", "推理小说", "奇幻小说",
310
+ "玄幻小说", "恐怖", "悬疑", "惊悚", "武侠小说", ], inputs=[novel_type])
311
+
312
+ written_paras = gr.Textbox(
313
+ label="Written Paragraphs (editable)", max_lines=23, lines=23) if "en" == lang_opt else gr.Textbox(
314
+ label="文章内容 (可编辑)", max_lines=23, lines=23)
315
+
316
+ with gr.Column():
317
+ if "en" == lang_opt:
318
+ gr.Markdown("### Memory Module\n")
319
+ elif lang_opt in ["zh1", "zh2"]:
320
+ gr.Markdown("### 剧情模型\n")
321
+
322
+ short_memory = gr.Textbox(
323
+ label="Short-Term Memory (editable)", max_lines=3, lines=3) if "en" == lang_opt else gr.Textbox(
324
+ label="短期记忆 (可编辑)", max_lines=3, lines=3)
325
+ long_memory = gr.Textbox(
326
+ label="Long-Term Memory (editable)", max_lines=6, lines=6) if "en" == lang_opt else gr.Textbox(
327
+ label="长期记忆 (可编辑)", max_lines=6, lines=6)
328
+
329
+ if "en" == lang_opt:
330
+ gr.Markdown("### Instruction Module\n")
331
+ elif lang_opt in ["zh1", "zh2"]:
332
+ gr.Markdown("### 选项模型\n")
333
+
334
+ with gr.Row():
335
+ instruction1 = gr.Textbox(
336
+ label="Instruction 1", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
337
+ label="指令1", max_lines=3, lines=3, interactive=False)
338
+ instruction2 = gr.Textbox(
339
+ label="Instruction 2", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
340
+ label="指令2", max_lines=3, lines=3, interactive=False)
341
+ instruction3 = gr.Textbox(
342
+ label="Instruction 3", max_lines=3, lines=3, interactive=False) if "en" == lang_opt else gr.Textbox(
343
+ label="指令3", max_lines=3, lines=3, interactive=False)
344
+ with gr.Row():
345
+ with gr.Column(scale=1, min_width=100):
346
+ selected_plan = gr.Radio(
347
+ ["Instruction 1", "Instruction 2", "Instruction 3"], label="Instruction Selection",) if "en" == lang_opt else gr.Radio(["指令 1", "指令 2", "指令 3"], label="指令 选择",)
348
+ with gr.Column(scale=3, min_width=300):
349
+ selected_instruction = gr.Textbox(
350
+ label="Selected Instruction (editable)", max_lines=5, lines=5) if "en" == lang_opt else gr.Textbox(
351
+ label="在上一步骤中被选择的 (可编辑)", max_lines=5, lines=5)
352
+
353
+ btn_step = gr.Button("Next Step", variant="primary") if "en" == lang_opt else gr.Button(
354
+ "下一步", variant="primary")
355
+
356
+ btn_init.click(init, inputs=[novel_type, description], outputs=[
357
+ short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
358
+ btn_step.click(controled_step, inputs=[short_memory, long_memory, selected_instruction, written_paras], outputs=[
359
+ short_memory, long_memory, written_paras, instruction1, instruction2, instruction3])
360
+ selected_plan.select(on_select, inputs=[
361
+ instruction1, instruction2, instruction3], outputs=[selected_instruction])
362
+
363
+ with gr.Tab("Model-Config"):
364
+ model_opt_radio = gr.Radio(["OpenAI", "ChatGLM-6B", "Vicuna-7B"], value="OpenAI", label="model",
365
+ info="select language you preferred. Default is English.",
366
+ interactive=True
367
+ )
368
+
369
+ reload_button = gr.Button("Reload/重新加载")
370
+ reload_button.click(reload_model, show_progress=True,
371
+ inputs=[model_opt_radio],
372
+ outputs=[novel_type])
373
+
374
+ demo.queue(concurrency_count=1)
 
375
 
376
  if __name__ == "__main__":
377
  demo.launch(show_error=True, show_api=False)