Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,24 @@ import gradio as gr
|
|
| 2 |
import pytesseract
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
-
# Tesseract
|
| 6 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
| 7 |
|
| 8 |
-
#
|
| 9 |
def evaluate_solution(image):
|
| 10 |
"""
|
| 11 |
-
์๊ธ์จ ์ด๋ฏธ์ง๋ฅผ
|
| 12 |
์ฑ์ทจ๊ธฐ์ค์ ๋ฐ๋ผ ํ๊ฐ ๋ฐ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ํจ์.
|
| 13 |
"""
|
| 14 |
try:
|
| 15 |
# OCR๋ก ์ด๋ฏธ์ง์์ ํ
์คํธ ์ถ์ถ
|
| 16 |
extracted_text = pytesseract.image_to_string(image, lang="kor")
|
| 17 |
|
| 18 |
-
# ์ด๊ธฐ
|
| 19 |
score = 0
|
| 20 |
feedback = []
|
| 21 |
|
| 22 |
-
#
|
| 23 |
if "ํผํฉ ๊ณ์ฐ" in extracted_text:
|
| 24 |
feedback.append("ํผํฉ ๊ณ์ฐ ํ์ด๊ฐ ํฌํจ๋์์ต๋๋ค.")
|
| 25 |
score += 30
|
|
@@ -38,19 +38,12 @@ def evaluate_solution(image):
|
|
| 38 |
else:
|
| 39 |
feedback.append("๋ถ์ ๋๋ ์์ ์ฐ์ฐ์ด ๋๋ฝ๋์์ต๋๋ค.")
|
| 40 |
|
| 41 |
-
# ๊ฒฐ๊ณผ ๋ฐํ
|
| 42 |
-
return
|
| 43 |
-
"์ถ์ถ๋ ํ
์คํธ": extracted_text,
|
| 44 |
-
"์ ์": score,
|
| 45 |
-
"ํผ๋๋ฐฑ": "\n".join(feedback)
|
| 46 |
-
}
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
"์ ์": 0,
|
| 52 |
-
"ํผ๋๋ฐฑ": f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 53 |
-
}
|
| 54 |
|
| 55 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
| 56 |
with gr.Blocks() as demo:
|
|
@@ -69,5 +62,5 @@ with gr.Blocks() as demo:
|
|
| 69 |
outputs=[output_text, output_score, output_feedback]
|
| 70 |
)
|
| 71 |
|
| 72 |
-
# ์คํ
|
| 73 |
demo.launch()
|
|
|
|
| 2 |
import pytesseract
|
| 3 |
from PIL import Image
|
| 4 |
|
| 5 |
+
# Tesseract ๊ฒฝ๋ก ์ค์ (Hugging Face Spaces์์๋ ๊ธฐ๋ณธ ์ค์น๋ Tesseract ์ฌ์ฉ)
|
| 6 |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract"
|
| 7 |
|
| 8 |
+
# ํ๊ฐ ํจ์ ์ ์
|
| 9 |
def evaluate_solution(image):
|
| 10 |
"""
|
| 11 |
+
์
๋ก๋๋ ์๊ธ์จ ์ด๋ฏธ์ง๋ฅผ OCR๋ก ํ
์คํธ๋ก ๋ณํํ๊ณ ,
|
| 12 |
์ฑ์ทจ๊ธฐ์ค์ ๋ฐ๋ผ ํ๊ฐ ๋ฐ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ ํจ์.
|
| 13 |
"""
|
| 14 |
try:
|
| 15 |
# OCR๋ก ์ด๋ฏธ์ง์์ ํ
์คํธ ์ถ์ถ
|
| 16 |
extracted_text = pytesseract.image_to_string(image, lang="kor")
|
| 17 |
|
| 18 |
+
# ์ด๊ธฐ ์ ์์ ํผ๋๋ฐฑ ์ค์
|
| 19 |
score = 0
|
| 20 |
feedback = []
|
| 21 |
|
| 22 |
+
# ์์: 6ํ๋
์ํ ์ฑ์ทจ๊ธฐ์ค ๊ธฐ๋ฐ ํ๊ฐ (ํผํฉ ๊ณ์ฐ, ์ฝ์์ ๋ฐฐ์, ๋ถ์์ ์์ ์ฐ์ฐ)
|
| 23 |
if "ํผํฉ ๊ณ์ฐ" in extracted_text:
|
| 24 |
feedback.append("ํผํฉ ๊ณ์ฐ ํ์ด๊ฐ ํฌํจ๋์์ต๋๋ค.")
|
| 25 |
score += 30
|
|
|
|
| 38 |
else:
|
| 39 |
feedback.append("๋ถ์ ๋๋ ์์ ์ฐ์ฐ์ด ๋๋ฝ๋์์ต๋๋ค.")
|
| 40 |
|
| 41 |
+
# ๊ฒฐ๊ณผ ๋ฐํ (ํ
์คํธ, ์ ์, ํผ๋๋ฐฑ)
|
| 42 |
+
return extracted_text, score, "\n".join(feedback)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
except Exception as e:
|
| 45 |
+
# ์ค๋ฅ ๋ฐ์ ์ ๊ธฐ๋ณธ๊ฐ ๋ฐํ
|
| 46 |
+
return "", 0, f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
| 49 |
with gr.Blocks() as demo:
|
|
|
|
| 62 |
outputs=[output_text, output_score, output_feedback]
|
| 63 |
)
|
| 64 |
|
| 65 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 66 |
demo.launch()
|