Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from datetime import datetime
|
|
| 4 |
import gradio as gr
|
| 5 |
from dateutil import parser
|
| 6 |
|
|
|
|
| 7 |
def _get_scene_titles(storydata):
|
| 8 |
scene_titles = {}
|
| 9 |
choice_names = {}
|
|
@@ -26,20 +27,18 @@ def _print_text_component(comp, output_lines):
|
|
| 26 |
def _print_dialog_component(comp, config, output_lines):
|
| 27 |
character_key = comp.get("characterAssetId")
|
| 28 |
character_name = config.get("characterMap", {}).get(character_key, {}).get("characterName")
|
| 29 |
-
dialog = comp["dialog"]
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
print()
|
| 37 |
-
output_lines.append(
|
| 38 |
-
|
| 39 |
-
print(dialog)
|
| 40 |
-
output_lines.append(dialog)
|
| 41 |
-
output_lines.append("")
|
| 42 |
print()
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
def _print_jump_component(comp, scene_titles, output_lines):
|
|
@@ -179,6 +178,8 @@ def format_story(storydata):
|
|
| 179 |
|
| 180 |
# Story title
|
| 181 |
|
|
|
|
|
|
|
| 182 |
title = storydata.get("name", "Untitled")
|
| 183 |
#_write_to_file(file, f"# {title} #")
|
| 184 |
#_write_to_file(file, "")
|
|
@@ -262,7 +263,7 @@ def format_story(storydata):
|
|
| 262 |
for comp in scene.get("components", []):
|
| 263 |
_print_component(comp, variables, scene_titles, choice_names, config, output_lines, background_dic)
|
| 264 |
|
| 265 |
-
|
| 266 |
|
| 267 |
def process_story(file):
|
| 268 |
|
|
@@ -274,11 +275,11 @@ def process_story(file):
|
|
| 274 |
|
| 275 |
iface = gr.Interface(
|
| 276 |
fn=process_story,
|
| 277 |
-
inputs=gr.File(type=
|
| 278 |
outputs="text",
|
| 279 |
title="Story Formatter",
|
| 280 |
description="Upload your JSON file and get the formatted story"
|
| 281 |
)
|
| 282 |
|
| 283 |
if __name__ == "__main__":
|
| 284 |
-
iface.launch()
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from dateutil import parser
|
| 6 |
|
| 7 |
+
|
| 8 |
def _get_scene_titles(storydata):
|
| 9 |
scene_titles = {}
|
| 10 |
choice_names = {}
|
|
|
|
| 27 |
def _print_dialog_component(comp, config, output_lines):
|
| 28 |
character_key = comp.get("characterAssetId")
|
| 29 |
character_name = config.get("characterMap", {}).get(character_key, {}).get("characterName")
|
| 30 |
+
dialog = comp["dialog"].replace("\n", " ")
|
| 31 |
+
|
| 32 |
+
if character_name:
|
| 33 |
+
dialog_line = f"{character_name}: {dialog}"
|
| 34 |
+
print(dialog_line)
|
| 35 |
+
output_lines.append(dialog_line)
|
| 36 |
+
else:
|
| 37 |
+
print(dialog)
|
| 38 |
+
output_lines.append(dialog)
|
| 39 |
+
|
|
|
|
|
|
|
|
|
|
| 40 |
print()
|
| 41 |
+
output_lines.append("")
|
| 42 |
|
| 43 |
|
| 44 |
def _print_jump_component(comp, scene_titles, output_lines):
|
|
|
|
| 178 |
|
| 179 |
# Story title
|
| 180 |
|
| 181 |
+
|
| 182 |
+
#with open(output_file, "w", encoding="utf-8") as file:
|
| 183 |
title = storydata.get("name", "Untitled")
|
| 184 |
#_write_to_file(file, f"# {title} #")
|
| 185 |
#_write_to_file(file, "")
|
|
|
|
| 263 |
for comp in scene.get("components", []):
|
| 264 |
_print_component(comp, variables, scene_titles, choice_names, config, output_lines, background_dic)
|
| 265 |
|
| 266 |
+
return "\n".join(output_lines)
|
| 267 |
|
| 268 |
def process_story(file):
|
| 269 |
|
|
|
|
| 275 |
|
| 276 |
iface = gr.Interface(
|
| 277 |
fn=process_story,
|
| 278 |
+
inputs=gr.File(type='filepath'),
|
| 279 |
outputs="text",
|
| 280 |
title="Story Formatter",
|
| 281 |
description="Upload your JSON file and get the formatted story"
|
| 282 |
)
|
| 283 |
|
| 284 |
if __name__ == "__main__":
|
| 285 |
+
iface.launch(share=True)
|