Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pytesseract | |
from PIL import Image | |
# Tesseract κ²½λ‘ μ€μ | |
# Hugging Face Spacesμμλ κΈ°λ³Έμ μΌλ‘ "/usr/bin/tesseract" κ²½λ‘μ μ€μΉλμ΄ μμ΅λλ€. | |
# λ‘컬 νκ²½μμ μ€ν μ, μλ κ²½λ‘λ₯Ό μμ μ Tesseract μ€μΉ κ²½λ‘λ‘ λ³κ²½νμΈμ. | |
pytesseract.pytesseract.tesseract_cmd = "/usr/bin/tesseract" | |
# νκ° ν¨μ μ μ | |
def evaluate_solution(image): | |
""" | |
μ λ‘λλ μκΈμ¨ μ΄λ―Έμ§λ₯Ό OCRλ‘ ν μ€νΈλ‘ λ³ννκ³ , | |
μ±μ·¨κΈ°μ€μ λ°λΌ νκ° λ° νΌλλ°±μ μ 곡νλ ν¨μ. | |
""" | |
try: | |
# OCRλ‘ μ΄λ―Έμ§μμ ν μ€νΈ μΆμΆ | |
extracted_text = pytesseract.image_to_string(image, lang="kor") | |
# μ΄κΈ° μ μμ νΌλλ°± μ€μ | |
score = 0 | |
feedback = [] | |
# μμ: 6νλ μν μ±μ·¨κΈ°μ€ κΈ°λ° νκ° (νΌν© κ³μ°, μ½μμ λ°°μ, λΆμμ μμ μ°μ°) | |
if "νΌν© κ³μ°" in extracted_text: | |
feedback.append("νΌν© κ³μ° νμ΄κ° ν¬ν¨λμμ΅λλ€.") | |
score += 30 | |
else: | |
feedback.append("νΌν© κ³μ° νμ΄κ° λλ½λμμ΅λλ€.") | |
if "μ½μμ λ°°μ" in extracted_text: | |
feedback.append("μ½μμ λ°°μ κ΄λ ¨ νμ΄κ° ν¬ν¨λμμ΅λλ€.") | |
score += 30 | |
else: | |
feedback.append("μ½μμ λ°°μ κ΄λ ¨ νμ΄κ° λλ½λμμ΅λλ€.") | |
if "λΆμμ λ§μ κ³Ό λΊμ " in extracted_text or "μμμ κ³±μ κ³Ό λλμ " in extracted_text: | |
feedback.append("λΆμ λλ μμ μ°μ°μ΄ ν¬ν¨λμμ΅λλ€.") | |
score += 40 | |
else: | |
feedback.append("λΆμ λλ μμ μ°μ°μ΄ λλ½λμμ΅λλ€.") | |
# κ²°κ³Ό λ°ν (ν μ€νΈ, μ μ, νΌλλ°±) | |
return extracted_text, score, "\n".join(feedback) | |
except Exception as e: | |
# μ€λ₯ λ°μ μ κΈ°λ³Έκ° λ°ν | |
return "", 0, f"μ€λ₯ λ°μ: {str(e)}" | |
# Gradio μΈν°νμ΄μ€ κ΅¬μ± | |
with gr.Blocks() as demo: | |
gr.Markdown("# μ΄λ±νκ΅ 6νλ μν λ¬Έμ νμ΄ νκ° μμ€ν ") | |
with gr.Row(): | |
image_input = gr.Image(label="μκΈμ¨ μ΄λ―Έμ§ μ λ‘λ", type="pil") | |
output_text = gr.Textbox(label="μΆμΆλ ν μ€νΈ") | |
output_score = gr.Number(label="μ μ") | |
output_feedback = gr.Textbox(label="νΌλλ°±") | |
submit_button = gr.Button("νκ°νκΈ°") | |
submit_button.click( | |
evaluate_solution, | |
inputs=image_input, | |
outputs=[output_text, output_score, output_feedback] | |
) | |
# μ ν리μΌμ΄μ μ€ν | |
demo.launch() | |