Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -76,9 +76,10 @@ GENRE_EXAMPLES = {
|
|
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.8 # Slightly increased for more creative responses
|
81 |
TOP_P = 0.95
|
|
|
82 |
|
83 |
def get_examples_for_genre(genre):
|
84 |
"""Get example prompts specific to the selected genre"""
|
@@ -189,14 +190,11 @@ def respond(
|
|
189 |
delta = response_chunk.choices[0].delta.content
|
190 |
if delta:
|
191 |
bot_message += delta
|
192 |
-
#
|
193 |
-
if len(bot_message.strip())
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
new_history.append((message, bot_message))
|
198 |
-
# Yield in the new dictionary format for Gradio
|
199 |
-
yield format_history_for_gradio(new_history)
|
200 |
except Exception as e:
|
201 |
error_message = f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"
|
202 |
broken_history = chat_history + [(message, error_message)]
|
@@ -222,11 +220,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
222 |
with gr.Column(scale=3):
|
223 |
# Chat window + user input
|
224 |
chatbot = gr.Chatbot(
|
225 |
-
height=
|
226 |
-
bubble_full_width=
|
227 |
show_copy_button=True,
|
228 |
avatar_images=(None, "🧙"),
|
229 |
-
type="messages"
|
|
|
|
|
|
|
230 |
)
|
231 |
msg = gr.Textbox(
|
232 |
placeholder="Describe what you want to do next in the story...",
|
|
|
76 |
# 2. Add constants at the top for magic numbers
|
77 |
MAX_HISTORY_LENGTH = 20
|
78 |
MEMORY_WINDOW = 10
|
79 |
+
MAX_TOKENS = 2048 # Doubled for longer responses
|
80 |
TEMPERATURE = 0.8 # Slightly increased for more creative responses
|
81 |
TOP_P = 0.95
|
82 |
+
MIN_RESPONSE_LENGTH = 200 # Minimum characters before yielding response
|
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 |
+
# Only yield complete responses
|
194 |
+
if len(bot_message.strip()) >= MIN_RESPONSE_LENGTH and "Option 3:" in bot_message:
|
195 |
+
new_history = chat_history.copy()
|
196 |
+
new_history.append((message, bot_message))
|
197 |
+
yield format_history_for_gradio(new_history)
|
|
|
|
|
|
|
198 |
except Exception as e:
|
199 |
error_message = f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"
|
200 |
broken_history = chat_history + [(message, error_message)]
|
|
|
220 |
with gr.Column(scale=3):
|
221 |
# Chat window + user input
|
222 |
chatbot = gr.Chatbot(
|
223 |
+
height=700, # Increased height
|
224 |
+
bubble_full_width=True, # Allow bubbles to use full width
|
225 |
show_copy_button=True,
|
226 |
avatar_images=(None, "🧙"),
|
227 |
+
type="messages",
|
228 |
+
container=True,
|
229 |
+
scale=1,
|
230 |
+
min_width=800 # Ensure minimum width
|
231 |
)
|
232 |
msg = gr.Textbox(
|
233 |
placeholder="Describe what you want to do next in the story...",
|