tkdehf2 commited on
Commit
0b288d9
Β·
verified Β·
1 Parent(s): 52eb579
Files changed (1) hide show
  1. 1 +0 -71
1 DELETED
@@ -1,71 +0,0 @@
1
- # ν•„μš”ν•œ 라이브러리 μ„€μΉ˜
2
- # !pip install transformers gradio pytesseract pillow
3
-
4
- from transformers import pipeline
5
- import gradio as gr
6
- from PIL import Image
7
- import pytesseract
8
-
9
- # 1. μ΄λ―Έμ§€μ—μ„œ ν…μŠ€νŠΈ μΆ”μΆœ (OCR)
10
- def extract_text_from_image(image):
11
- """
12
- μ—…λ‘œλ“œλœ 이미지λ₯Ό ν…μŠ€νŠΈλ‘œ λ³€ν™˜ν•˜λŠ” ν•¨μˆ˜.
13
- """
14
- img = Image.open(image)
15
- text = pytesseract.image_to_string(img)
16
- return text
17
-
18
- # 2. λ‹΅μ•ˆ 채점 ν•¨μˆ˜
19
- def grade_answer(question, student_answer):
20
- """
21
- 질문과 ν•™μƒμ˜ λ‹΅μ•ˆμ„ μž…λ ₯λ°›μ•„ μ±„μ ν•˜λŠ” ν•¨μˆ˜.
22
- """
23
- # Hugging Face의 사전 ν•™μŠ΅λœ λͺ¨λΈμ„ μ‚¬μš©ν•˜μ—¬ λ‹΅μ•ˆμ„ ν‰κ°€ν•©λ‹ˆλ‹€.
24
- model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2")
25
- result = model(f"Question: {question} Answer: {student_answer}")
26
-
27
- # 긍정적(Positive)인지 뢀정적(Negative)인지 κ²°κ³Ό λ°˜ν™˜
28
- return result[0]['label']
29
-
30
- # 3. 문제 풀이 생성 ν•¨μˆ˜
31
- def generate_solution(question):
32
- """
33
- μ§ˆλ¬Έμ— λŒ€ν•œ 해섀을 μžλ™μœΌλ‘œ μƒμ„±ν•˜λŠ” ν•¨μˆ˜.
34
- """
35
- generator = pipeline('text-generation', model='gpt2')
36
- solution = generator(f"Explain the solution to the following question: {question}", max_length=150)
37
-
38
- # μƒμ„±λœ 풀이 λ°˜ν™˜
39
- return solution[0]['generated_text']
40
-
41
- # 4. Gradio μΈν„°νŽ˜μ΄μŠ€ 처리 ν•¨μˆ˜
42
- def process_image(image, student_answer):
43
- """
44
- μ—…λ‘œλ“œλœ 이미지λ₯Ό μ²˜λ¦¬ν•˜κ³ , ν•™μƒμ˜ λ‹΅μ•ˆμ„ μ±„μ ν•˜λ©°, 문제 풀이λ₯Ό μ œκ³΅ν•˜λŠ” ν•¨μˆ˜.
45
- """
46
- # μ΄λ―Έμ§€μ—μ„œ ν…μŠ€νŠΈ μΆ”μΆœ (OCR)
47
- question_text = extract_text_from_image(image)
48
-
49
- # 채점 κ²°κ³Ό
50
- grade = grade_answer(question_text, student_answer)
51
-
52
- # 문제 풀이 생성
53
- solution = generate_solution(question_text)
54
-
55
- # κ²°κ³Ό λ°˜ν™˜
56
- return f"문제 λ‚΄μš©:\n{question_text}\n\n채점 κ²°κ³Ό: {grade}\n\n풀이:\n{solution}"
57
-
58
- # 5. Gradio UI μ„€μ • 및 μ‹€ν–‰
59
- interface = gr.Interface(
60
- fn=process_image, # μ²˜λ¦¬ν•  메인 ν•¨μˆ˜
61
- inputs=[
62
- gr.inputs.Image(type="file", label="문제 이미지 μ—…λ‘œλ“œ"), # 이미지 μž…λ ₯
63
- gr.inputs.Textbox(lines=2, placeholder="ν•™μƒμ˜ λ‹΅μ•ˆμ„ μž…λ ₯ν•˜μ„Έμš”", label="ν•™μƒμ˜ λ‹΅μ•ˆ") # λ‹΅μ•ˆ μž…λ ₯
64
- ],
65
- outputs="text", # 좜λ ₯ ν˜•μ‹ (ν…μŠ€νŠΈ)
66
- title="μžλ™ 채점 및 풀이 제곡 μ‹œμŠ€ν…œ",
67
- description="μ΄ˆλ“±ν•™κ΅ 6ν•™λ…„ 학생듀이 ν‘Ό 문제λ₯Ό μ‚¬μ§„μœΌλ‘œ 올리면 μžλ™μœΌλ‘œ μ±„μ ν•˜κ³  해섀을 μ œκ³΅ν•©λ‹ˆλ‹€."
68
- )
69
-
70
- # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰ (Hugging Face Spacesμ—μ„œ μ‹€ν–‰ κ°€λŠ₯)
71
- interface.launch()