Fix mobile rendering and stabilize output display
Browse filesImplemented st.empty() placeholders and unique session keys to ensure output persistence across mobile browsers. Refactored the composition column to prevent UI freezing during long-running model inference.
app.py
CHANGED
|
@@ -76,15 +76,19 @@ with col1:
|
|
| 76 |
|
| 77 |
with col2:
|
| 78 |
st.subheader("Output")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
if generate_btn:
|
| 80 |
with st.spinner("Model is writing..."):
|
| 81 |
-
# Load Engine
|
| 82 |
model, tokenizer = load_studio_engine()
|
| 83 |
|
| 84 |
-
# Build Inference Prompt
|
| 85 |
prompt = build_inference_prompt(genre, artist, title)
|
| 86 |
|
| 87 |
-
# Generate
|
| 88 |
raw_output = execute_generation(
|
| 89 |
model, tokenizer, prompt,
|
| 90 |
max_tokens=token_limit,
|
|
@@ -92,7 +96,19 @@ with col2:
|
|
| 92 |
do_sample=True
|
| 93 |
)
|
| 94 |
|
| 95 |
-
# Post-process
|
| 96 |
clean_lyrics = format_lyrics(raw_output)
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
with col2:
|
| 78 |
st.subheader("Output")
|
| 79 |
+
|
| 80 |
+
# Create a persistent placeholder for the output
|
| 81 |
+
output_placeholder = st.empty()
|
| 82 |
+
|
| 83 |
if generate_btn:
|
| 84 |
with st.spinner("Model is writing..."):
|
| 85 |
+
# Load Engine
|
| 86 |
model, tokenizer = load_studio_engine()
|
| 87 |
|
| 88 |
+
# Build Inference Prompt
|
| 89 |
prompt = build_inference_prompt(genre, artist, title)
|
| 90 |
|
| 91 |
+
# Generate Lyrics
|
| 92 |
raw_output = execute_generation(
|
| 93 |
model, tokenizer, prompt,
|
| 94 |
max_tokens=token_limit,
|
|
|
|
| 96 |
do_sample=True
|
| 97 |
)
|
| 98 |
|
| 99 |
+
# Post-process formatting
|
| 100 |
clean_lyrics = format_lyrics(raw_output)
|
| 101 |
+
|
| 102 |
+
# Update the placeholder specifically
|
| 103 |
+
output_placeholder.text_area(
|
| 104 |
+
"Final Draft",
|
| 105 |
+
clean_lyrics,
|
| 106 |
+
height=400,
|
| 107 |
+
key="lyrics_output" # adding a key helps mobile state persistence
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
st.download_button(
|
| 111 |
+
"Export as TXT",
|
| 112 |
+
clean_lyrics,
|
| 113 |
+
file_name=f"{title}_lyrics.txt"
|
| 114 |
+
)
|