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

Update app.py

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