lxtung95 commited on
Commit
9d142db
·
verified ·
1 Parent(s): d461af3

Fix mobile rendering and stabilize output display

Browse files

Implemented 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.

Files changed (1) hide show
  1. app.py +22 -6
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 (This uses the @st.cache_resource to avoid repeated loading)
82
  model, tokenizer = load_studio_engine()
83
 
84
- # Build Inference Prompt using the modular data script
85
  prompt = build_inference_prompt(genre, artist, title)
86
 
87
- # Generate using the universal engine in metrics script
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 and display
96
  clean_lyrics = format_lyrics(raw_output)
97
- st.text_area("Final Draft", clean_lyrics, height=400)
98
- st.download_button("Export as TXT", clean_lyrics, file_name=f"{title}_lyrics.txt")
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )