Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -75,11 +75,11 @@ GENRE_EXAMPLES = {
|
|
75 |
|
76 |
# 2. Add constants at the top for magic numbers
|
77 |
MAX_HISTORY_LENGTH = 20
|
78 |
-
MEMORY_WINDOW = 10
|
79 |
-
MAX_TOKENS =
|
80 |
-
TEMPERATURE = 0.
|
81 |
TOP_P = 0.95
|
82 |
-
MIN_RESPONSE_LENGTH =
|
83 |
|
84 |
def get_examples_for_genre(genre):
|
85 |
"""Get example prompts specific to the selected genre"""
|
@@ -190,8 +190,8 @@ def respond(
|
|
190 |
delta = response_chunk.choices[0].delta.content
|
191 |
if delta:
|
192 |
bot_message += delta
|
193 |
-
#
|
194 |
-
if len(bot_message.strip()) >= MIN_RESPONSE_LENGTH
|
195 |
new_history = chat_history.copy()
|
196 |
new_history.append((message, bot_message))
|
197 |
yield format_history_for_gradio(new_history)
|
@@ -214,6 +214,8 @@ def save_story(chat_history):
|
|
214 |
|
215 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
216 |
gr.Markdown("# 🔮 Interactive Story Time")
|
|
|
|
|
217 |
gr.Markdown("Create a completely unique literary world, one choice at a time. Dare to explore the unknown.")
|
218 |
|
219 |
with gr.Row():
|
@@ -287,10 +289,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
287 |
# 4) Connect each starter button:
|
288 |
for starter_button in starter_buttons:
|
289 |
starter_button.click(
|
290 |
-
fn=
|
291 |
-
inputs=[starter_button
|
292 |
outputs=[chatbot],
|
293 |
queue=False
|
|
|
|
|
|
|
|
|
|
|
294 |
)
|
295 |
|
296 |
# 5) Dynamically update the 4 buttons if the user changes the genre
|
@@ -332,3 +339,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
332 |
# Run the app
|
333 |
if __name__ == "__main__":
|
334 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
75 |
|
76 |
# 2. Add constants at the top for magic numbers
|
77 |
MAX_HISTORY_LENGTH = 20
|
78 |
+
MEMORY_WINDOW = 5 # Reduced from 10 to limit context
|
79 |
+
MAX_TOKENS = 1024 # Reduced from 2048 for faster responses
|
80 |
+
TEMPERATURE = 0.7 # Slightly reduced for faster convergence
|
81 |
TOP_P = 0.95
|
82 |
+
MIN_RESPONSE_LENGTH = 100 # Reduced from 200 for quicker display
|
83 |
|
84 |
def get_examples_for_genre(genre):
|
85 |
"""Get example prompts specific to the selected genre"""
|
|
|
190 |
delta = response_chunk.choices[0].delta.content
|
191 |
if delta:
|
192 |
bot_message += delta
|
193 |
+
# Yield more frequently
|
194 |
+
if len(bot_message.strip()) >= MIN_RESPONSE_LENGTH:
|
195 |
new_history = chat_history.copy()
|
196 |
new_history.append((message, bot_message))
|
197 |
yield format_history_for_gradio(new_history)
|
|
|
214 |
|
215 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
216 |
gr.Markdown("# 🔮 Interactive Story Time")
|
217 |
+
with gr.Row():
|
218 |
+
status_message = gr.Markdown("Ready to begin your adventure...", visible=True)
|
219 |
gr.Markdown("Create a completely unique literary world, one choice at a time. Dare to explore the unknown.")
|
220 |
|
221 |
with gr.Row():
|
|
|
289 |
# 4) Connect each starter button:
|
290 |
for starter_button in starter_buttons:
|
291 |
starter_button.click(
|
292 |
+
fn=lambda x: ((x, ""), []), # Show user message immediately
|
293 |
+
inputs=[starter_button],
|
294 |
outputs=[chatbot],
|
295 |
queue=False
|
296 |
+
).then( # Chain the response after showing user message
|
297 |
+
fn=respond,
|
298 |
+
inputs=[starter_button, chatbot, genre, full_memory],
|
299 |
+
outputs=[chatbot],
|
300 |
+
queue=True
|
301 |
)
|
302 |
|
303 |
# 5) Dynamically update the 4 buttons if the user changes the genre
|
|
|
339 |
# Run the app
|
340 |
if __name__ == "__main__":
|
341 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
342 |
+
|