reab5555 commited on
Commit
8244923
·
verified ·
1 Parent(s): 17b932a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -55,7 +55,7 @@ class LazyPipeline:
55
  "text-generation",
56
  model=model,
57
  tokenizer=tokenizer,
58
- max_new_tokens=2048,
59
  temperature=0.6,
60
  )
61
  return self.pipeline
@@ -181,7 +181,7 @@ def process_input(input_file, progress=gr.Progress()):
181
  with open(srt_path, 'r', encoding='utf-8') as file:
182
  content = file.read()
183
  words, tokens = count_words_and_tokens(content)
184
- input_info = f"Video transcribed. Words: {words}, Tokens: {tokens}"
185
  else:
186
  return "Unsupported file format. Please upload a TXT, PDF, or video file.", None, None, None, None, None, None
187
 
@@ -258,7 +258,7 @@ def update_visibility_and_charts(status, exec_time, lang, info, attachments, big
258
  gr.update(value=exec_time, visible=True),
259
  gr.update(value=lang, visible=True),
260
  gr.update(value=info, visible=True),
261
- ] + [None for _ in range(12)]
262
 
263
  for analysis_text in [attachments, bigfive, personalities]:
264
  speakers_data = extract_speaker_data(analysis_text)
@@ -283,15 +283,12 @@ def update_visibility_and_charts(status, exec_time, lang, info, attachments, big
283
 
284
  print("Number of charts created:", len(charts))
285
 
286
- # Ensure we always return the same number of outputs
287
- chart_outputs = charts + [None] * (12 - len(charts))
288
-
289
  return [
290
  gr.update(value=status, visible=True),
291
  gr.update(value=exec_time, visible=True),
292
  gr.update(value=lang, visible=True),
293
  gr.update(value=info, visible=True),
294
- ] + chart_outputs
295
 
296
  def create_interface():
297
  with gr.Blocks() as iface:
@@ -313,18 +310,26 @@ def create_interface():
313
  bigfive_output = gr.Textbox(visible=False)
314
  personalities_output = gr.Textbox(visible=False)
315
 
316
- charts = [gr.Plot(visible=True) for _ in range(12)] # Assuming maximum 12 charts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
  input_file.upload(
319
- fn=process_input,
320
  inputs=[input_file],
321
- outputs=[status_text, execution_time, detected_language, input_info,
322
- attachments_output, bigfive_output, personalities_output]
323
- ).then(
324
- fn=update_visibility_and_charts,
325
- inputs=[status_text, execution_time, detected_language, input_info,
326
- attachments_output, bigfive_output, personalities_output],
327
- outputs=[status_text, execution_time, detected_language, input_info] + charts
328
  )
329
 
330
  return iface
 
55
  "text-generation",
56
  model=model,
57
  tokenizer=tokenizer,
58
+ max_new_tokens=4096,
59
  temperature=0.6,
60
  )
61
  return self.pipeline
 
181
  with open(srt_path, 'r', encoding='utf-8') as file:
182
  content = file.read()
183
  words, tokens = count_words_and_tokens(content)
184
+ input_info = f"Input Words: {words} / Input Tokens: {tokens}"
185
  else:
186
  return "Unsupported file format. Please upload a TXT, PDF, or video file.", None, None, None, None, None, None
187
 
 
258
  gr.update(value=exec_time, visible=True),
259
  gr.update(value=lang, visible=True),
260
  gr.update(value=info, visible=True),
261
+ ] + [] # No charts to return
262
 
263
  for analysis_text in [attachments, bigfive, personalities]:
264
  speakers_data = extract_speaker_data(analysis_text)
 
283
 
284
  print("Number of charts created:", len(charts))
285
 
 
 
 
286
  return [
287
  gr.update(value=status, visible=True),
288
  gr.update(value=exec_time, visible=True),
289
  gr.update(value=lang, visible=True),
290
  gr.update(value=info, visible=True),
291
+ ] + charts
292
 
293
  def create_interface():
294
  with gr.Blocks() as iface:
 
310
  bigfive_output = gr.Textbox(visible=False)
311
  personalities_output = gr.Textbox(visible=False)
312
 
313
+ # Container for dynamically created charts
314
+ chart_container = gr.Column()
315
+
316
+ def process_and_update(input_file):
317
+ # First, process the input
318
+ results = process_input(input_file)
319
+
320
+ # Then, create and update charts
321
+ chart_outputs = update_visibility_and_charts(*results)
322
+
323
+ # Create new chart components based on the number of charts
324
+ new_charts = [gr.Plot(visible=True) for _ in range(len(chart_outputs) - 4)] # -4 for the non-chart outputs
325
+
326
+ # Update the chart container
327
+ return chart_outputs[:4] + [gr.Column(new_charts)]
328
 
329
  input_file.upload(
330
+ fn=process_and_update,
331
  inputs=[input_file],
332
+ outputs=[status_text, execution_time, detected_language, input_info, chart_container]
 
 
 
 
 
 
333
  )
334
 
335
  return iface