Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #14

Merged
merged 23 commits into from
Nov 20, 2024
Merged

Dev #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crud/difficulty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
def decomposition(korean_word: str):
korean_word = re.sub(r'[!"#$%&\'()*+,-./:;<=>?@\[\]^_\`{|}~\\\\]','', korean_word)
# 초성 리스트. 00 ~ 18
CHOSUNG_LIST = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
# 중성 리스트. 00 ~ 20
Expand Down
27 changes: 22 additions & 5 deletions crud/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,34 @@ class ScoreResponse(BaseModel):
score: int
analysis: List[ScoreAnalysis]# from pydantic import List

from main import ScoreRequest
def score_crud(score: ScoreRequest):
def score_crud(score):
workbook = score.workbook
answer = score.answer

"""
ocr request
답안이 저장된 s3 주소 (string)
ocr response
{문제 번호(int): 답안(string), ..., 문제 번호: 답안}
"""
atext = ocr(answer)
ascore = simillarity(answer)

"""
simillarity request
workbook
{문제 번호(int): 문제(string), ..., 문제 번호: 문제}
answer
{문제 번호(int): 문제(string), ..., 문제 번호: 문제}

simillarity response
{문제 번호(int): 점수(int), ..., 문제 번호(int): 점수(int)}

"""
ascore = simillarity(workbook, answer)

# {1: [('맏이가', '마지가')], 2: [('굳이', '구지'), ('그렇게까지', '그러케까 지')], 4: [('새로', '세로')]}
wrong_list = extract_wa(workbook, atext)
wk = list(workbook)
print(wrong_list)

response = {}

Expand Down Expand Up @@ -93,7 +110,7 @@ def ocr(a):
6: "밥머고 영화 볼 싸람?"
}

def simillarity(a):
def simillarity(workbook, a):
return {1: 90, 2:80, 3:100, 4:80, 5:100, 6:20}

def extract_wa(workbook, atext):
Expand Down
27 changes: 17 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class PronounceRule(str, Enum):
기식음화 = "기식음화"

class ClaudeRequest(BaseModel):
age: int = Field(default=11)
difficulty: int = Field(default=3)
rule: PronounceRule
count: int = Field(default=5)



@app.post("/phonological_rules")
async def analysis_pronounce(text: Dict[int, str] = Body(
Expand Down Expand Up @@ -60,14 +58,14 @@ async def generate_claude(request: ClaudeRequest):
max_tokens=1000,
# 다양한 결과값을 얻기 위해 temperature 값 조절
temperature=0.5,
system="너는 음운 규칙별 받아쓰기 문제를 생성하는거야. 음운 규칙에는 구개음화, 연음화, 경음화, 유음화, 비음화, 음운규칙 없음, 겹받침 쓰기, 기식음화가 있어.\n내가 'n살 난이도로 [m]유형으로 k문제 만들어줘' 라고 하면 맞춰서 받아쓰기 문제를 만들어줘.\nn: 8~13 (초등학교 1학년~6학년)\nm: 구개음화, 연음화, 경음화, 유음화, 비음화, 음운규칙 없음, 겹받침 쓰기, 기식음화\nk: 1~15\n답변 형식:\n문제번호:문제 형태로 json형식으로 반환",
system="너는 음운 규칙별 받아쓰기 문제를 생성하는거야. 음운 규칙에는 구개음화, 연음화, 경음화, 유음화, 비음화, 음운규칙 없음, 겹받침 쓰기, 기식음화가 있어.\n내가 'n 난이도로 [m]유형으로 k문제 만들어줘' 라고 하면 맞춰서 받아쓰기 문제를 만들어줘.\nn: 1~5 (초등학교 기준, 1: 단어, 2: 쉬운 단어가 있는 간단한 문장, 3: 쉬운 단어가 있는 짧은 문장, 4: 짧은 문장, 5: 문장)\nm: 구개음화, 연음화, 경음화, 유음화, 비음화, 음운규칙 없음, 겹받침 쓰기, 기식음화\n답변 형식:\n문제번호:문제 형태로 json형식으로 반환",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"{request.age}살 난이도로 [{request.rule}] 유형으로 {request.count}문제 만들어줘. (seed: {datetime.now().isoformat()})"
"text": f"{request.difficulty} 난이도로 [{request.rule}] 유형으로 {request.count}문제 만들어줘. (seed: {datetime.now().isoformat()})"
}
]
}
Expand Down Expand Up @@ -103,19 +101,28 @@ async def calc_difficulty(text: DifficultyRequest):
'ㅒ':7, 'ㅠ':7,
}

#pronounce 추출해서 해당하는 부분만 스코어링
s = text.text
b_list, m_list = difficulty_dec(s)
analysis = pronounce.pronounce_crud(s)

spro = ''

for k, v in analysis.items():
if not v: continue
spro+=''.join(v)

b_list, m_list = difficulty_dec(spro)
b_grade_sum = sum(b_grade.get(b) for b in b_list)
m_grade_sum = sum(m_grade.get(m) for m in m_list)
return b_grade_sum + m_grade_sum
total = (b_grade_sum+m_grade_sum)//5
if total>5: total=5
if total<1: total=1
return total

class ScoreRequest(BaseModel):
workbook: dict[int, str] = Field(description="문제집")
answer: str = Field(description="답안 S3 주소")




@app.post("/score")
async def score_endpoint(s: ScoreRequest = Body(
example={
Expand Down
Loading