Spaces:
Runtime error
Runtime error
Commit
·
b2bd8fb
1
Parent(s):
5dcee28
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
|
|
4 |
import openai
|
5 |
|
6 |
|
|
|
7 |
def continueStory(blank, messageHistory):
|
8 |
|
9 |
openai.api_key = os.environ['OPENAI_KEY']
|
@@ -22,6 +23,8 @@ def continueStory(blank, messageHistory):
|
|
22 |
return story, messageHistory
|
23 |
|
24 |
|
|
|
|
|
25 |
with gr.Blocks(css='''
|
26 |
.gradio-container {
|
27 |
display: flex;
|
@@ -29,7 +32,7 @@ with gr.Blocks(css='''
|
|
29 |
justify-content: center;
|
30 |
align-items: center;
|
31 |
background-image: url('file=https://cdn.discordapp.com/attachments/941582479117127680/1080730421425344542/rodotcom_colorful_abstract_illustration_for_the_background_of_c_f1b331d7-6493-4a33-9063-345d31a66ddb.png');
|
32 |
-
|
33 |
}
|
34 |
|
35 |
h1 {
|
@@ -46,10 +49,6 @@ with gr.Blocks(css='''
|
|
46 |
color: white;
|
47 |
}
|
48 |
|
49 |
-
#row {
|
50 |
-
width: 40%;
|
51 |
-
margin: 0 auto;
|
52 |
-
}
|
53 |
|
54 |
label {
|
55 |
font-size: 1.25rem;
|
@@ -74,17 +73,12 @@ with gr.Blocks(css='''
|
|
74 |
border-radius: 5px;
|
75 |
cursor: pointer;
|
76 |
transition: all 0.2s ease-in-out;
|
77 |
-
width: 50%;
|
78 |
}
|
79 |
|
80 |
.gradio-button:hover {
|
81 |
background-color: #0c7cd5;
|
82 |
}
|
83 |
|
84 |
-
#main_col {
|
85 |
-
margin: 0 auto;
|
86 |
-
}
|
87 |
-
|
88 |
|
89 |
|
90 |
''') as demo:
|
@@ -94,10 +88,45 @@ with gr.Blocks(css='''
|
|
94 |
<p style="color: white; font-size: 1.25rem; margin-bottom: 2rem; color: white;">Let's see where your imagination can take you!</p>
|
95 |
</div>
|
96 |
''')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
def show_feedback_text():
|
102 |
return {feedbackForm: gr.update(visible=True)}
|
103 |
|
@@ -106,7 +135,7 @@ with gr.Blocks(css='''
|
|
106 |
|
107 |
def generateStory(character):
|
108 |
|
109 |
-
openai.api_key = os.environ['OPENAI_KEY']
|
110 |
|
111 |
messageHistory=[
|
112 |
{"role": "system", "content": "You are co-writing assistant that will help me generate an interactive storytelling game. You are going to generate one paragraph at a time but you are going to leave a blank somewhere in the last line of the paragraph. The user will have to fill this blank in order to generate the next paragraph. You have to write in the style of Julia Donaldson and Doctor Seuss. Make the story funny and exciting. For more context, the game works as follows. 1. You generate one, and only one paragraph, with a blank somewhere in the last line of the paragraph. 2. The user tells you how they want to fill the blank. 3. You generate the next paragraph based on the user’s response to continue the story. This next paragraph also has a blank somewhere in the last line of the paragraph. 4. The user tells you how they want to fill the blank. And so on. Please make sure that when you write a paragraph, there is only one blank and it is at the end of the last line."},
|
@@ -124,7 +153,7 @@ with gr.Blocks(css='''
|
|
124 |
|
125 |
def finishStory(blank, messageHistory):
|
126 |
|
127 |
-
openai.api_key = os.environ['OPENAI_KEY']
|
128 |
|
129 |
messageHistory.append({"role": "user", "content": blank + "\n\nNow bring the story to a close. Write the necessary paragraphs to make it have a happy or funny ending. No need to leave a blank anymore."})
|
130 |
|
@@ -140,49 +169,12 @@ with gr.Blocks(css='''
|
|
140 |
return story, messageHistory
|
141 |
|
142 |
def createNewStory():
|
143 |
-
return {character: gr.update(value=""), story_output: gr.update(value="")}
|
144 |
|
145 |
def hideContinueBtn():
|
146 |
return {continueStoryCol: gr.update(visible=False), newStoryCol: gr.update(visible=True), finishCol: gr.update(visible=False)}
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
character = gr.Textbox(label='Who will be the main character?', elem_id = 'theme', placeholder="i.e. Diego, an 11-year-old pirate")
|
151 |
-
|
152 |
-
|
153 |
-
messageHistory = gr.State()
|
154 |
-
|
155 |
-
beginBtn = gr.Button("Start!", elem_id="generate-btn")
|
156 |
-
|
157 |
-
story_output = gr.Textbox(label='Story')
|
158 |
-
|
159 |
-
blank = gr.Textbox(label='How will you fill the blank?', elem_id = 'blank')
|
160 |
-
|
161 |
-
with gr.Column(visible=True) as continueStoryCol:
|
162 |
-
continueBtn = gr.Button("Continue Story", elem_id="continue-btn")
|
163 |
-
|
164 |
-
with gr.Column(visible=False) as newStoryCol:
|
165 |
-
newStoryBtn = gr.Button("Create New Story", elem_id="new-story-btn")
|
166 |
|
167 |
-
with gr.Column(visible=True) as finishCol:
|
168 |
-
finishBtn = gr.Button("Finish Story", elem_id="finish-btn")
|
169 |
-
|
170 |
-
provideFeedbackBtn = gr.Button("Provide Feedback", elem_id="feedback-btn")
|
171 |
|
172 |
-
with gr.Column(visible=False) as feedbackForm:
|
173 |
-
gr.Radio(["1", "2", "3", "4", "5"], label="How would you rate the story")
|
174 |
-
feedback_text = gr.Textbox(label='Any other comments?')
|
175 |
-
submitFeedbackBtn = gr.Button("Submit Feedback", elem_id="submit-feedback-btn")
|
176 |
-
|
177 |
-
with gr.Column(visible=False) as thankyou:
|
178 |
-
|
179 |
-
feedback_text = gr.HTML("<h2>Thanks for your feeback!</h2>")
|
180 |
-
|
181 |
-
with gr.Column(visible=False) as mesHistoryCol:
|
182 |
-
|
183 |
-
messageHistoryTextBox = gr.Textbox(label='How will you fill the blank?', elem_id = 'blank', value=messageHistory)
|
184 |
-
|
185 |
-
|
186 |
beginBtn.click(generateStory, inputs=[character], outputs=[story_output, messageHistory])
|
187 |
|
188 |
continueBtn.click(continueStory, inputs=[blank, messageHistory], outputs=[story_output, messageHistory])
|
@@ -194,7 +186,7 @@ with gr.Blocks(css='''
|
|
194 |
|
195 |
submitFeedbackBtn.click(submitFeedback, [], [thankyou, feedbackForm])
|
196 |
|
197 |
-
newStoryBtn.click(createNewStory, [], [character, story_output])
|
198 |
|
199 |
|
200 |
-
demo.launch(debug=True, share=
|
|
|
4 |
import openai
|
5 |
|
6 |
|
7 |
+
|
8 |
def continueStory(blank, messageHistory):
|
9 |
|
10 |
openai.api_key = os.environ['OPENAI_KEY']
|
|
|
23 |
return story, messageHistory
|
24 |
|
25 |
|
26 |
+
|
27 |
+
|
28 |
with gr.Blocks(css='''
|
29 |
.gradio-container {
|
30 |
display: flex;
|
|
|
32 |
justify-content: center;
|
33 |
align-items: center;
|
34 |
background-image: url('file=https://cdn.discordapp.com/attachments/941582479117127680/1080730421425344542/rodotcom_colorful_abstract_illustration_for_the_background_of_c_f1b331d7-6493-4a33-9063-345d31a66ddb.png');
|
35 |
+
|
36 |
}
|
37 |
|
38 |
h1 {
|
|
|
49 |
color: white;
|
50 |
}
|
51 |
|
|
|
|
|
|
|
|
|
52 |
|
53 |
label {
|
54 |
font-size: 1.25rem;
|
|
|
73 |
border-radius: 5px;
|
74 |
cursor: pointer;
|
75 |
transition: all 0.2s ease-in-out;
|
|
|
76 |
}
|
77 |
|
78 |
.gradio-button:hover {
|
79 |
background-color: #0c7cd5;
|
80 |
}
|
81 |
|
|
|
|
|
|
|
|
|
82 |
|
83 |
|
84 |
''') as demo:
|
|
|
88 |
<p style="color: white; font-size: 1.25rem; margin-bottom: 2rem; color: white;">Let's see where your imagination can take you!</p>
|
89 |
</div>
|
90 |
''')
|
91 |
+
with gr.Row(elem_id='row'):
|
92 |
+
character = gr.Textbox(label='Who will be the main character?', elem_id = 'theme', placeholder="i.e. Diego, an 11-year-old pirate")
|
93 |
+
|
94 |
+
messageHistory = gr.State()
|
95 |
+
|
96 |
+
beginBtn = gr.Button("Start!", elem_id="generate-btn")
|
97 |
+
|
98 |
+
story_output = gr.Textbox(label='Story')
|
99 |
+
|
100 |
+
blank = gr.Textbox(label='How will you fill the blank?', elem_id = 'blank')
|
101 |
+
|
102 |
+
with gr.Column(visible=True) as continueStoryCol:
|
103 |
+
continueBtn = gr.Button("Continue Story", elem_id="continue-btn")
|
104 |
+
|
105 |
+
with gr.Column(visible=False) as newStoryCol:
|
106 |
+
newStoryBtn = gr.Button("Create New Story", elem_id="new-story-btn")
|
107 |
+
|
108 |
+
with gr.Column(visible=True) as finishCol:
|
109 |
+
finishBtn = gr.Button("Finish Story", elem_id="finish-btn")
|
110 |
+
|
111 |
+
provideFeedbackBtn = gr.Button("Provide Feedback", elem_id="feedback-btn")
|
112 |
+
|
113 |
+
with gr.Column(visible=False) as feedbackForm:
|
114 |
+
gr.Radio(["1", "2", "3", "4", "5"], label="How would you rate the story")
|
115 |
+
feedback_text = gr.Textbox(label='Any other comments?')
|
116 |
+
submitFeedbackBtn = gr.Button("Submit Feedback", elem_id="submit-feedback-btn")
|
117 |
+
|
118 |
+
with gr.Column(visible=False) as thankyou:
|
119 |
+
|
120 |
+
feedback_text = gr.HTML("<h2>Thanks for your feeback!</h2>")
|
121 |
+
|
122 |
+
with gr.Column(visible=False) as mesHistoryCol:
|
123 |
+
|
124 |
+
messageHistoryTextBox = gr.Textbox(label='How will you fill the blank?', elem_id = 'blank', value=messageHistory)
|
125 |
+
|
126 |
|
127 |
+
# the submit feedback btn needs to: send the feedback,
|
128 |
+
# hide the elements and provide a message saying thanks for your feedback
|
129 |
+
|
130 |
def show_feedback_text():
|
131 |
return {feedbackForm: gr.update(visible=True)}
|
132 |
|
|
|
135 |
|
136 |
def generateStory(character):
|
137 |
|
138 |
+
openai.api_key = openai.api_key = os.environ['OPENAI_KEY']
|
139 |
|
140 |
messageHistory=[
|
141 |
{"role": "system", "content": "You are co-writing assistant that will help me generate an interactive storytelling game. You are going to generate one paragraph at a time but you are going to leave a blank somewhere in the last line of the paragraph. The user will have to fill this blank in order to generate the next paragraph. You have to write in the style of Julia Donaldson and Doctor Seuss. Make the story funny and exciting. For more context, the game works as follows. 1. You generate one, and only one paragraph, with a blank somewhere in the last line of the paragraph. 2. The user tells you how they want to fill the blank. 3. You generate the next paragraph based on the user’s response to continue the story. This next paragraph also has a blank somewhere in the last line of the paragraph. 4. The user tells you how they want to fill the blank. And so on. Please make sure that when you write a paragraph, there is only one blank and it is at the end of the last line."},
|
|
|
153 |
|
154 |
def finishStory(blank, messageHistory):
|
155 |
|
156 |
+
openai.api_key = openai.api_key = os.environ['OPENAI_KEY']
|
157 |
|
158 |
messageHistory.append({"role": "user", "content": blank + "\n\nNow bring the story to a close. Write the necessary paragraphs to make it have a happy or funny ending. No need to leave a blank anymore."})
|
159 |
|
|
|
169 |
return story, messageHistory
|
170 |
|
171 |
def createNewStory():
|
172 |
+
return {character: gr.update(value=""), story_output: gr.update(value=""), blank: gr.update(value="")}
|
173 |
|
174 |
def hideContinueBtn():
|
175 |
return {continueStoryCol: gr.update(visible=False), newStoryCol: gr.update(visible=True), finishCol: gr.update(visible=False)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
|
|
|
|
|
|
|
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
beginBtn.click(generateStory, inputs=[character], outputs=[story_output, messageHistory])
|
179 |
|
180 |
continueBtn.click(continueStory, inputs=[blank, messageHistory], outputs=[story_output, messageHistory])
|
|
|
186 |
|
187 |
submitFeedbackBtn.click(submitFeedback, [], [thankyou, feedbackForm])
|
188 |
|
189 |
+
newStoryBtn.click(createNewStory, [], [character, story_output, blank])
|
190 |
|
191 |
|
192 |
+
demo.launch(debug=True, share=True)
|