aliceblue11 commited on
Commit
ba0c99a
·
verified ·
1 Parent(s): 6b5fc3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -1
app.py CHANGED
@@ -336,10 +336,33 @@ def clear_all():
336
  """모든 입력 초기화"""
337
  return None, None, "", "", ""
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  def clear_all_tab2():
340
  """탭2의 모든 입력 초기화"""
341
  return None, "", "", "", ""
342
 
 
 
 
 
343
  # Gradio 인터페이스 생성
344
  def create_interface():
345
  # 앱 시작 시 환경 변수 확인
@@ -464,6 +487,69 @@ def create_interface():
464
  show_label=False
465
  )
466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
  with gr.TabItem("✏️ 변경사항 요청"):
468
  with gr.Row():
469
  with gr.Column():
@@ -537,6 +623,24 @@ def create_interface():
537
  outputs=[image1, image2, comparison_output, text1_output, text2_output]
538
  )
539
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
540
  # 이벤트 연결 - 탭2 (변경사항 요청)
541
  extract_text_btn.click(
542
  fn=extract_text_only,
@@ -572,4 +676,4 @@ if __name__ == "__main__":
572
  server_port=7860,
573
  share=True,
574
  show_error=True
575
- )
 
336
  """모든 입력 초기화"""
337
  return None, None, "", "", ""
338
 
339
+ def compare_image_and_text(image_text, input_text, api_key_input):
340
+ """이미지에서 추출된 텍스트와 입력된 텍스트 비교"""
341
+ # 환경 변수 우선 확인 및 API 설정
342
+ if not model:
343
+ config_result = configure_api(api_key_input)
344
+ if "❌" in config_result:
345
+ return input_text, config_result
346
+
347
+ if not image_text.strip():
348
+ return input_text, "먼저 이미지에서 텍스트를 추출해주세요."
349
+
350
+ if not input_text.strip():
351
+ return input_text, "비교할 텍스트를 입력해주세요."
352
+
353
+ # 비교 결과 생성
354
+ comparison = compare_texts(image_text, input_text)
355
+
356
+ return input_text, comparison
357
+
358
  def clear_all_tab2():
359
  """탭2의 모든 입력 초기화"""
360
  return None, "", "", "", ""
361
 
362
+ def clear_all_tab3():
363
+ """탭3의 모든 입력 초기화"""
364
+ return None, "", "", "", ""
365
+
366
  # Gradio 인터페이스 생성
367
  def create_interface():
368
  # 앱 시작 시 환경 변수 확인
 
487
  show_label=False
488
  )
489
 
490
+ with gr.TabItem("📷 이미지+텍스트"):
491
+ with gr.Row():
492
+ with gr.Column():
493
+ gr.Markdown("### 📷 원본 이미지 업로드")
494
+ image_tab3 = gr.Image(
495
+ label="원본 이미지",
496
+ type="pil",
497
+ height=300
498
+ )
499
+ extract_text_btn_tab3 = gr.Button(
500
+ "📝 텍스트 추출",
501
+ variant="secondary",
502
+ size="lg"
503
+ )
504
+ with gr.Column():
505
+ gr.Markdown("### ✏️ 텍스트 입력")
506
+ text_input_tab3 = gr.Textbox(
507
+ label="비교할 텍스트를 입력하세요",
508
+ placeholder="여기에 비교하고 싶은 텍스트를 입력하세요...",
509
+ lines=10,
510
+ max_lines=15
511
+ )
512
+
513
+ with gr.Row():
514
+ compare_text_btn = gr.Button(
515
+ "🔍 텍스트 비교",
516
+ variant="primary",
517
+ size="lg"
518
+ )
519
+
520
+ with gr.Row():
521
+ with gr.Column():
522
+ gr.Markdown("### 📄 추출된 텍스트")
523
+ with gr.Row():
524
+ extracted_text_tab3 = gr.Textbox(
525
+ label="원본 이미지 텍스트",
526
+ lines=10,
527
+ max_lines=15,
528
+ show_copy_button=True
529
+ )
530
+ input_text_display = gr.Textbox(
531
+ label="입력된 텍스트",
532
+ lines=10,
533
+ max_lines=15,
534
+ show_copy_button=True,
535
+ interactive=False
536
+ )
537
+
538
+ with gr.Row():
539
+ with gr.Column():
540
+ gr.Markdown("### 📊 텍스트 차이점 분석")
541
+ comparison_output_tab3 = gr.HTML(
542
+ label="텍스트 비교 결과",
543
+ show_label=False
544
+ )
545
+
546
+ with gr.Row():
547
+ clear_btn_tab3 = gr.Button(
548
+ "🗑️ 초기화",
549
+ variant="secondary",
550
+ size="lg"
551
+ )
552
+
553
  with gr.TabItem("✏️ 변경사항 요청"):
554
  with gr.Row():
555
  with gr.Column():
 
623
  outputs=[image1, image2, comparison_output, text1_output, text2_output]
624
  )
625
 
626
+ # 이벤트 연결 - 탭3 (이미지+텍스트)
627
+ extract_text_btn_tab3.click(
628
+ fn=extract_text_only,
629
+ inputs=[image_tab3, api_key_input],
630
+ outputs=[extracted_text_tab3]
631
+ )
632
+
633
+ compare_text_btn.click(
634
+ fn=compare_image_and_text,
635
+ inputs=[extracted_text_tab3, text_input_tab3, api_key_input],
636
+ outputs=[input_text_display, comparison_output_tab3]
637
+ )
638
+
639
+ clear_btn_tab3.click(
640
+ fn=clear_all_tab3,
641
+ outputs=[image_tab3, text_input_tab3, extracted_text_tab3, input_text_display, comparison_output_tab3]
642
+ )
643
+
644
  # 이벤트 연결 - 탭2 (변경사항 요청)
645
  extract_text_btn.click(
646
  fn=extract_text_only,
 
676
  server_port=7860,
677
  share=True,
678
  show_error=True
679
+ )