Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,23 +40,21 @@ def ocr_inference(img, lang):
|
|
40 |
return txts
|
41 |
|
42 |
def make_flashcards(words, language):
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
cards.append(card)
|
59 |
-
return cards
|
60 |
|
61 |
words=text_inference(text, "korean")
|
62 |
print("OUTPUT TOUT OUETOI EIFJ IEFJ",words)
|
|
|
40 |
return txts
|
41 |
|
42 |
def make_flashcards(words, language):
|
43 |
+
|
44 |
+
system_prompt = (
|
45 |
+
f"Given the following {language} words, define each word and create an example sentence, with an explanation"
|
46 |
+
|
47 |
+
)
|
48 |
+
user_prompt = f"{system_prompt}\n\nText:\n{text}"
|
49 |
+
|
50 |
+
input_ids = tokenizer.apply_chat_template([{"role": "user", "content": user_prompt}], return_tensors="pt").to(model.device)
|
51 |
+
output_ids = model.generate(input_ids, max_new_tokens=256)
|
52 |
+
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
53 |
+
|
54 |
+
# Parse response: take last line, split by commas
|
55 |
+
last_line = output_text.strip().split("\n")[-1]
|
56 |
+
output = [w.strip() for w in last_line.split(":") if w.strip()]
|
57 |
+
|
|
|
|
|
58 |
|
59 |
words=text_inference(text, "korean")
|
60 |
print("OUTPUT TOUT OUETOI EIFJ IEFJ",words)
|