Jessiesj commited on
Commit
06df4c1
·
verified ·
1 Parent(s): 76c627a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -111,12 +111,6 @@ if user_input and style_or_opening:
111
 
112
  # Post - processing
113
  def format_script(text):
114
- # # Force - correct the scene title format (e.g., "Scene 1" -> "### Scene 1")
115
- # text = re.sub(r"Scene(\d+)", r"### Scene\1", text)
116
- # # Remove extra symbols
117
- # text = re.sub(r"[<>()]{2,}|\[?\]?", "", text)
118
- # # Ensure action descriptions are wrapped in square brackets
119
- # return re.sub(r"(?<=\n)\s*([^\[\n]+?)\s*(?=\n)", r"[\1]", text)
120
  return text
121
 
122
  # Display the result
@@ -131,9 +125,31 @@ if user_input and style_or_opening:
131
  st.stop()
132
 
133
  # 2. Generate the storyboard
134
- with st.status("🎥 Converting to a storyboard script...", expanded=True) as status:
135
  try:
136
- # JSON template guidance
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  json_template = """{
138
  "scenes": [
139
  {
@@ -146,31 +162,33 @@ if user_input and style_or_opening:
146
  ]
147
  }"""
148
 
149
- # Generate the storyboard
150
  storyboard = storyboard_pipe(
151
- f"Convert the following script into a storyboard JSON, strictly following the template:\n{json_template}\nScript content: {cleaned[:800]}", # Key modification point
152
  max_length=1500,
153
  temperature=0.3
154
  )[0]["generated_text"]
155
 
156
- # Format repair process
157
- storyboard = storyboard.replace("'", '"') # Unify quotes
158
- storyboard = re.search(r'\{.*\}', storyboard, re.DOTALL).group() # Extract JSON
159
-
160
- # Parse and validate
 
 
 
161
  parsed = json.loads(storyboard)
162
- status.update(label="Storyboard generation completed ✅", state="complete")
163
- st.subheader("Storyboard Script")
164
- st.json(parsed)
165
 
166
- except json.JSONDecodeError:
167
- status.update(label="Storyboard parsing failed ❌", state="error")
168
- st.warning("Automatically fixing the storyboard format...")
169
- storyboard = "{" + storyboard.split("{", 1)[-1].rsplit("}", 1)[0] + "}"
170
- st.code(storyboard)
171
  except Exception as e:
172
- status.update(label="Storyboard generation error ❌", state="error")
173
- st.error(f"Storyboard generation error: {str(e)}")
 
 
 
 
 
 
 
174
 
175
 
176
  # 3. 生成配乐
 
111
 
112
  # Post - processing
113
  def format_script(text):
 
 
 
 
 
 
114
  return text
115
 
116
  # Display the result
 
125
  st.stop()
126
 
127
  # 2. Generate the storyboard
128
+ with st.status("🎥 Converting to storyboard script...", expanded=True) as status:
129
  try:
130
+ # 示例数据模板
131
+ sample_storyboard = """
132
+ {
133
+ "scenes": [
134
+ {
135
+ "scene_number": 1,
136
+ "location": "Abandoned Space Station (INT. Dystopian Future)",
137
+ "characters": ["Eve", "R2-D9"],
138
+ "camera_angle": "Wide shot showing decaying corridors",
139
+ "action": "Eve scans walls with her holographic projector, R2-D9 beeps nervously"
140
+ },
141
+ {
142
+ "scene_number": 2,
143
+ "location": "Alien Wasteland (EXT. Toxic Sunset)",
144
+ "characters": ["Eve", "Mutant Leader"],
145
+ "camera_angle": "Low-angle shot of Eve aiming plasma rifle",
146
+ "action": "Mutant leader growls, acid rain hisses on Eve's protective suit"
147
+ }
148
+ ]
149
+ }
150
+ """
151
+
152
+ # JSON模板引导
153
  json_template = """{
154
  "scenes": [
155
  {
 
162
  ]
163
  }"""
164
 
165
+ # 生成分镜
166
  storyboard = storyboard_pipe(
167
+ f"Convert to storyboard JSON: {cleaned[:800]}",
168
  max_length=1500,
169
  temperature=0.3
170
  )[0]["generated_text"]
171
 
172
+ # 增强的格式修复
173
+ storyboard = (
174
+ storyboard.replace("'", '"')
175
+ .replace("None", '""')
176
+ .replace("True", "true")
177
+ .replace("False", "false")
178
+ )
179
+ storyboard = re.search(r'\{.*\}', storyboard, re.DOTALL).group()
180
  parsed = json.loads(storyboard)
 
 
 
181
 
 
 
 
 
 
182
  except Exception as e:
183
+ st.warning(f"Using sample storyboard due to error: {str(e)}")
184
+ parsed = json.loads(sample_storyboard) # 回退到示例数据
185
+ status.update(label="⚠️ Using sample storyboard", state="warning")
186
+
187
+ finally:
188
+ status.update(label="Storyboard ready", state="complete")
189
+ st.subheader("Storyboard Script")
190
+ st.json(parsed)
191
+ st.caption("*Note: If using sample data, edit the JSON before proceeding*")
192
 
193
 
194
  # 3. 生成配乐