Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
demo = None #added to allow restart
|
| 4 |
+
|
| 5 |
+
def start_game(main_loop, share=False):
|
| 6 |
+
# added code to support restart
|
| 7 |
+
global demo
|
| 8 |
+
# If demo is already running, close it first
|
| 9 |
+
if demo is not None:
|
| 10 |
+
demo.close()
|
| 11 |
+
|
| 12 |
+
demo = gr.ChatInterface(
|
| 13 |
+
main_loop,
|
| 14 |
+
chatbot=gr.Chatbot(height=250, placeholder="Type 'start game' to begin"),
|
| 15 |
+
textbox=gr.Textbox(placeholder="What do you do next?", container=False, scale=7),
|
| 16 |
+
title="AI RPG",
|
| 17 |
+
# description="Ask Yes Man any question",
|
| 18 |
+
theme="soft",
|
| 19 |
+
examples=["Look around", "Continue the story"],
|
| 20 |
+
cache_examples=False,
|
| 21 |
+
retry_btn="Retry",
|
| 22 |
+
undo_btn="Undo",
|
| 23 |
+
clear_btn="Clear",
|
| 24 |
+
)
|
| 25 |
+
demo.launch(share=share, server_name="0.0.0.0")
|
| 26 |
+
|
| 27 |
+
def test_main_loop(message, history):
|
| 28 |
+
return 'Entered Action: ' + message
|
| 29 |
+
|
| 30 |
+
start_game(test_main_loop)
|