baohuynhbk14 commited on
Commit
bf30e1e
·
verified ·
1 Parent(s): a7d12bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -6
app.py CHANGED
@@ -94,7 +94,6 @@ model_t = Qwen3VLForConditionalGeneration.from_pretrained(
94
  trust_remote_code=True,
95
  torch_dtype=torch.float16).to(device).eval()
96
 
97
- # --- Các hàm hỗ trợ PDF (Từ Script 1) ---
98
  def convert_pdf_to_images(file_path: str, dpi: int = 200):
99
  if not file_path:
100
  return []
@@ -144,7 +143,6 @@ def navigate_pdf_page(direction: str, state: Dict[str, Any]):
144
  page_info_html = f'<div style="text-align:center;">Page {new_index + 1} / {total_pages}</div>'
145
  return image_preview, state, page_info_html
146
 
147
- # --- Hàm hỗ trợ Video (Từ Script 2) ---
148
  def downsample_video(video_path):
149
  """
150
  Downsamples the video to evenly spaced frames.
@@ -167,7 +165,6 @@ def downsample_video(video_path):
167
  vidcap.release()
168
  return frames
169
 
170
- # --- Các hàm Generate (Từ Script 2, với `generate_pdf` được thêm vào) ---
171
  @spaces.GPU
172
  def generate_image(model_name: str, text: str, image: Image.Image,
173
  max_new_tokens: int = 1024,
@@ -301,7 +298,6 @@ def generate_pdf(model_name: str, text: str, state: Dict[str, Any],
301
  else:
302
  yield "Invalid model selected.", "Invalid model selected."
303
  return
304
- # --- Kết thúc logic chọn model ---
305
 
306
  if not state or not state["pages"]:
307
  yield "Please upload a PDF file first.", "Please upload a PDF file first."
@@ -368,7 +364,7 @@ css = """
368
 
369
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
370
 
371
- # pdf_state = gr.State(value=get_initial_pdf_state())
372
 
373
  gr.Markdown("# 🎉**Qwen3-VL-Demo**🎉", elem_id="main-title")
374
  with gr.Row():
@@ -436,7 +432,6 @@ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
436
 
437
  pdf_submit.click(
438
  fn=generate_pdf,
439
- # Thêm 'model_choice' vào inputs
440
  inputs=[model_choice, pdf_query, pdf_state, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
441
  outputs=[output, markdown_output]
442
  )
 
94
  trust_remote_code=True,
95
  torch_dtype=torch.float16).to(device).eval()
96
 
 
97
  def convert_pdf_to_images(file_path: str, dpi: int = 200):
98
  if not file_path:
99
  return []
 
143
  page_info_html = f'<div style="text-align:center;">Page {new_index + 1} / {total_pages}</div>'
144
  return image_preview, state, page_info_html
145
 
 
146
  def downsample_video(video_path):
147
  """
148
  Downsamples the video to evenly spaced frames.
 
165
  vidcap.release()
166
  return frames
167
 
 
168
  @spaces.GPU
169
  def generate_image(model_name: str, text: str, image: Image.Image,
170
  max_new_tokens: int = 1024,
 
298
  else:
299
  yield "Invalid model selected.", "Invalid model selected."
300
  return
 
301
 
302
  if not state or not state["pages"]:
303
  yield "Please upload a PDF file first.", "Please upload a PDF file first."
 
364
 
365
  with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
366
 
367
+ pdf_state = gr.State(value=get_initial_pdf_state())
368
 
369
  gr.Markdown("# 🎉**Qwen3-VL-Demo**🎉", elem_id="main-title")
370
  with gr.Row():
 
432
 
433
  pdf_submit.click(
434
  fn=generate_pdf,
 
435
  inputs=[model_choice, pdf_query, pdf_state, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
436
  outputs=[output, markdown_output]
437
  )