Hyounggoo commited on
Commit
0dff0c6
Β·
verified Β·
1 Parent(s): f38f577

Upload 4 files

Browse files
Files changed (4) hide show
  1. KAIRO_Checklist_Config.json +28 -0
  2. README.md +4 -4
  3. app.py +41 -108
  4. requirements.txt +3 -4
KAIRO_Checklist_Config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "checklist_korean": [
3
+ "λ§žμΆ€λ²• (Orthography)",
4
+ "띄어쓰기 (Spacing Rules)",
5
+ "문법 였λ₯˜ (Grammatical Errors)",
6
+ "ν‘œμ€€μ–΄ κ·œμ • μœ„λ°˜ (Standard Language Regulation)",
7
+ "μ™Έλž˜μ–΄ ν‘œκΈ°λ²• μœ„λ°˜ (Loanword Orthography)",
8
+ "λ¬Έμž₯ ꡬ쑰 였λ₯˜ (Sentence Structure Error)",
9
+ "μ–΄νœ˜ μ μ ˆμ„± (Lexical Appropriateness)",
10
+ "쀑볡어/ꡰ더더기 제거 (Redundancy Elimination)",
11
+ "μ˜€νƒˆμž (Typographical Errors)",
12
+ "λ¬Έμž₯ λΆ€ν˜Έ μ‚¬μš© (Punctuation Usage)",
13
+ "어법 였λ₯˜ (Usage Error)",
14
+ "논리적 일관성 (Logical Coherence)",
15
+ "ν˜•μ‹μ  였λ₯˜ (Formatting Consistency)"
16
+ ],
17
+ "checklist_english": [
18
+ "Spelling (철자 였λ₯˜)",
19
+ "Grammar (문법 였λ₯˜)",
20
+ "Capitalization (λŒ€μ†Œλ¬Έμž 였λ₯˜)",
21
+ "Subject-Verb Agreement (μ£Όμ–΄-동사 일치)",
22
+ "Article Usage (κ΄€μ‚¬μ˜ μ μ ˆμ„±)",
23
+ "Tense Consistency (μ‹œμ œ 일관성)",
24
+ "Word Choice (μ–΄νœ˜ 선택)",
25
+ "Redundancy (쀑볡 ν‘œν˜„)",
26
+ "Tone (문체 및 일관성)"
27
+ ]
28
+ }
README.md CHANGED
@@ -1,3 +1,4 @@
 
1
  ---
2
  title: "KAIRO.ai"
3
  emoji: "🧠"
@@ -9,7 +10,6 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- # KAIRO.ai - 닀쀑 OCR 정확도 비ꡐ 및 병합
13
- - μ—¬λŸ¬ OCR μ—”μ§„ κ²°κ³Ό 비ꡐ
14
- - μœ μ‚¬λ„ 점수 ν‘œμ‹œ
15
- - 졜적 후보 μžλ™ 선택
 
1
+
2
  ---
3
  title: "KAIRO.ai"
4
  emoji: "🧠"
 
10
  pinned: false
11
  ---
12
 
13
+ # KAIRO.ai
14
+
15
+ AI 기반 PNG 이미지 ꡐ정 (OCR + GPT-4 Turbo + PPT 생성) μ‹œμŠ€ν…œμž…λ‹ˆλ‹€.
 
app.py CHANGED
@@ -1,119 +1,52 @@
1
 
2
  import streamlit as st
3
  from PIL import Image
4
- import pytesseract
5
- import easyocr
6
- from paddleocr import PaddleOCR
7
- import numpy as np
8
- from pptx import Presentation
9
- from pptx.util import Inches, Pt
10
- import os
11
  import io
12
- import tempfile
13
- import zipfile
14
- from difflib import SequenceMatcher
15
 
16
- st.set_page_config(layout="centered")
17
- st.markdown("<h1 style='text-align: center; font-size: 48px;'>🧠 KAIRO.ai - OCR 정확도 비ꡐ & 병합</h1>", unsafe_allow_html=True)
18
-
19
- st.sidebar.header("OCR μ—”μ§„ 선택")
20
- ocr_engines = st.sidebar.multiselect("μ‚¬μš©ν•  OCR 엔진을 μ„ νƒν•˜μ„Έμš”", ["Tesseract", "EasyOCR", "PaddleOCR"], default=["Tesseract", "EasyOCR"])
21
-
22
- uploaded_files = st.file_uploader("PNG λ˜λŠ” ZIP 파일 μ—…λ‘œλ“œ", type=["png", "zip"], accept_multiple_files=True)
23
-
24
- def normalize(text):
25
- return text.replace(" ", "").replace("\n", "").lower()
26
-
27
- def score_similarity(a, b):
28
- return SequenceMatcher(None, a, b).ratio()
29
-
30
- def extract_images(file):
31
- images = []
32
- if file.name.endswith(".zip"):
33
- with tempfile.TemporaryDirectory() as tmpdir:
34
- zip_path = os.path.join(tmpdir, file.name)
35
- with open(zip_path, "wb") as f:
36
- f.write(file.getbuffer())
37
- with zipfile.ZipFile(zip_path, 'r') as zip_ref:
38
- zip_ref.extractall(tmpdir)
39
- for root, _, files in os.walk(tmpdir):
40
- for name in files:
41
- if name.lower().endswith(".png"):
42
- images.append(Image.open(os.path.join(root, name)).convert("RGB"))
43
- else:
44
- images = [Image.open(file).convert("RGB")]
45
- return images
46
-
47
- def run_tesseract(img):
48
- return pytesseract.image_to_string(img, lang="kor+eng")
49
-
50
- def run_easyocr(img):
51
- reader = easyocr.Reader(['ko', 'en'], gpu=False)
52
- result = reader.readtext(np.array(img), detail=0)
53
- return "\n".join(result)
54
-
55
- def run_paddleocr(img):
56
- ocr = PaddleOCR(use_angle_cls=True, lang='korean')
57
- result = ocr.ocr(np.array(img), cls=True)
58
- return "\n".join([line[1][0] for block in result for line in block])
59
-
60
- def create_ppt(results):
61
- prs = Presentation()
62
- for idx, (img, all_texts, best_text, best_engine) in enumerate(results):
63
- slide = prs.slides.add_slide(prs.slide_layouts[5])
64
- title = slide.shapes.title
65
- title.text = f"파일 {idx+1} (졜적 μ—”μ§„: {best_engine})"
66
-
67
- left = Inches(0.5)
68
- top = Inches(1.0)
69
- width = Inches(8.5)
70
- height = Inches(5.5)
71
- txBox = slide.shapes.add_textbox(left, top, width, height)
72
- tf = txBox.text_frame
73
- for engine, text in all_texts.items():
74
- p = tf.add_paragraph()
75
- p.text = f"[{engine}]\n{text}\n"
76
- p.font.size = Pt(14)
77
- p = tf.add_paragraph()
78
- p.text = f"[μ΅œμ’… 선택 κ²°κ³Ό]\n{best_text}"
79
- p.font.size = Pt(16)
80
- return prs
81
 
82
  if uploaded_files:
83
- results = []
84
- for file in uploaded_files:
85
- images = extract_images(file)
86
- for img in images:
87
- ocr_texts = {}
88
- if "Tesseract" in ocr_engines:
89
- ocr_texts["Tesseract"] = run_tesseract(img)
90
- if "EasyOCR" in ocr_engines:
91
- ocr_texts["EasyOCR"] = run_easyocr(img)
92
- if "PaddleOCR" in ocr_engines:
93
- ocr_texts["PaddleOCR"] = run_paddleocr(img)
94
-
95
- st.image(img, caption="μ—…λ‘œλ“œ 이미지", use_column_width=True)
96
-
97
- # 비ꡐ κΈ°μ€€: 첫 엔진을 κΈ°μ€€μœΌλ‘œ μœ μ‚¬λ„ 계산
98
- base_engine = list(ocr_texts.keys())[0]
99
- base_text = normalize(ocr_texts[base_engine])
100
- scores = {engine: score_similarity(base_text, normalize(txt)) for engine, txt in ocr_texts.items()}
101
- best_engine = max(scores, key=scores.get)
102
- best_text = ocr_texts[best_engine]
103
 
104
- st.markdown("#### OCR κ²°κ³Ό 비ꡐ")
105
- for engine, text in ocr_texts.items():
106
- st.text_area(f"{engine} κ²°κ³Ό", text, height=150)
107
 
108
- st.markdown("#### μœ μ‚¬λ„ 점수")
109
- for engine, score in scores.items():
110
- st.write(f"{engine}: {round(score*100, 2)}%")
111
 
112
- st.success(f"βœ… 졜적 후보: {best_engine}")
113
- results.append((img, ocr_texts, best_text, best_engine))
 
114
 
115
- ppt = create_ppt(results)
116
- ppt_path = "/mnt/data/KAIRO_OCR_졜적결과.pptx"
117
- ppt.save(ppt_path)
118
- with open(ppt_path, "rb") as f:
119
- st.download_button("πŸ“₯ PPT λ‹€μš΄λ‘œλ“œ", data=f.read(), file_name="KAIRO_OCR_졜적결과.pptx")
 
1
 
2
  import streamlit as st
3
  from PIL import Image
 
 
 
 
 
 
 
4
  import io
 
 
 
5
 
6
+ st.set_page_config(page_title="KAIRO.ai", layout="wide")
7
+
8
+ # 닀크λͺ¨λ“œ ν† κΈ€ (우츑 상단)
9
+ col1, col2 = st.columns([8, 1])
10
+ with col2:
11
+ dark_mode = st.toggle("πŸŒ™", help="닀크 λͺ¨λ“œ μ „ν™˜")
12
+
13
+ # 쀑앙 μ •λ ¬ 타이틀, ν™•λŒ€
14
+ st.markdown(
15
+ "<h1 style='text-align: center; font-size: 3em;'>🧠 KAIRO.ai</h1>",
16
+ unsafe_allow_html=True
17
+ )
18
+
19
+ # 닀크λͺ¨λ“œ μŠ€νƒ€μΌ 적용
20
+ if dark_mode:
21
+ st.markdown("""
22
+ <style>
23
+ html, body, .stApp {
24
+ background-color: #1e1e1e;
25
+ color: #f0f0f0;
26
+ }
27
+ </style>
28
+ """, unsafe_allow_html=True)
29
+
30
+ ocr_engines = st.multiselect("🧠 OCR μ—”μ§„ 선택 (쀑볡 κ°€λŠ₯)", ["Tesseract", "EasyOCR", "PaddleOCR"], default=["Tesseract"])
31
+ checklist = st.multiselect("πŸ” κ²€μˆ˜ ν•­λͺ© 선택", ["μ˜€νƒˆμž", "띄어쓰기", "문법", "μ–΄νœ˜"], default=["μ˜€νƒˆμž", "띄어쓰기"])
32
+ uploaded_files = st.file_uploader("πŸ“Ž PNG μ—…λ‘œλ“œ (μ œν•œ μ—†μŒ)", type=["png"], accept_multiple_files=True)
33
+ api_key = st.text_input("πŸ” OpenAI API Key", type="password")
34
+
35
+ st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  if uploaded_files:
38
+ st.success(f"{len(uploaded_files)}μž₯ μ—…λ‘œλ“œ μ™„λ£Œ βœ…")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ estimated_tokens_per_file = 400
41
+ total_tokens = estimated_tokens_per_file * len(uploaded_files)
42
+ cost_estimate = total_tokens * 0.01 / 1000
43
 
44
+ st.markdown("### πŸ’° μ˜ˆμƒ λΉ„μš© μ•ˆλ‚΄ (GPT-4 Turbo κΈ°μ€€)")
45
+ st.markdown(f"- μ˜ˆμƒ 토큰 수: **{total_tokens} tokens**")
46
+ st.markdown(f"- μ˜ˆμƒ λΉ„μš©: **${cost_estimate:.4f}**")
47
 
48
+ st.info("πŸ‘‰ OCR μ‹€ν–‰ 쀑...")
49
+ st.info("πŸ‘‰ GPT ꡐ정 μ§„ν–‰ 쀑...")
50
+ st.info("πŸ‘‰ PPT 생성 쀑...")
51
 
52
+ st.warning("β€» 이 κΈ°λŠ₯은 데λͺ¨μš©μ΄λ©° μ‹€μ œ OCR/GPT 연동은 λ‹€μŒ λ²„μ „μ—μ„œ μž‘λ™ν•©λ‹ˆλ‹€.")
 
 
 
 
requirements.txt CHANGED
@@ -1,7 +1,6 @@
 
1
  streamlit
2
  pytesseract
3
- easyocr
4
- paddleocr
5
- python-pptx
6
  Pillow
7
- numpy
 
 
1
+
2
  streamlit
3
  pytesseract
 
 
 
4
  Pillow
5
+ python-pptx
6
+ openai