Update app.py
Browse files
app.py
CHANGED
@@ -73,40 +73,35 @@ else:
|
|
73 |
"Story:"
|
74 |
)
|
75 |
|
76 |
-
# 4) Generate story
|
77 |
-
with st.spinner("✍️ Generating story..."):
|
78 |
-
try:
|
79 |
-
story_out = story_client(
|
80 |
-
inputs=prompt,
|
81 |
-
parameters={
|
82 |
-
"max_new_tokens": 250,
|
83 |
-
"temperature": 0.7,
|
84 |
-
"top_p": 0.9,
|
85 |
-
"repetition_penalty": 1.1,
|
86 |
-
"do_sample": True
|
87 |
-
}
|
88 |
-
)
|
89 |
-
|
90 |
-
# Parse response
|
91 |
-
if isinstance(story_out, list):
|
92 |
-
story_text = story_out[0].get("generated_text", "")
|
93 |
-
else:
|
94 |
-
story_text = story_out.get("generated_text", "")
|
95 |
-
|
96 |
-
# Clean up output
|
97 |
-
story = story_text.split("Story:")[-1].strip()
|
98 |
-
|
99 |
-
except Exception as e:
|
100 |
-
st.error(f"🚨 Story generation failed: {str(e)}")
|
101 |
-
st.stop()
|
102 |
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
st.stop()
|
106 |
|
107 |
-
st.markdown("**Story:**")
|
108 |
-
st.write(story)
|
109 |
-
|
110 |
# 5) Text-to-Speech
|
111 |
with st.spinner("🔊 Converting to speech..."):
|
112 |
try:
|
|
|
73 |
"Story:"
|
74 |
)
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
复制代码
|
78 |
+
# 4) Generate story with corrected parameter format
|
79 |
+
with st.spinner("✍️ Generating story..."):
|
80 |
+
try:
|
81 |
+
story_out = story_client(
|
82 |
+
prompt,
|
83 |
+
max_new_tokens=250, # Direct keyword arguments
|
84 |
+
temperature=0.7,
|
85 |
+
top_p=0.9,
|
86 |
+
top_k=50,
|
87 |
+
repetition_penalty=1.1,
|
88 |
+
do_sample=True,
|
89 |
+
no_repeat_ngram_size=2
|
90 |
+
)
|
91 |
+
|
92 |
+
# Handle response format
|
93 |
+
if isinstance(story_out, list):
|
94 |
+
story_text = story_out[0].get("generated_text", "")
|
95 |
+
else: # Handle single-dictionary response
|
96 |
+
story_text = story_out.get("generated_text", "")
|
97 |
+
|
98 |
+
# Extract story content after last prompt mention
|
99 |
+
story = story_text.split("Story:")[-1].strip()
|
100 |
+
|
101 |
+
except Exception as e:
|
102 |
+
st.error(f"🚨 Story generation failed: {str(e)}")
|
103 |
st.stop()
|
104 |
|
|
|
|
|
|
|
105 |
# 5) Text-to-Speech
|
106 |
with st.spinner("🔊 Converting to speech..."):
|
107 |
try:
|