dimasdeffieux commited on
Commit
e2cf15d
·
verified ·
1 Parent(s): 595067f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -40,23 +40,21 @@ def ocr_inference(img, lang):
40
  return txts
41
 
42
  def make_flashcards(words, language):
43
- cards=[]
44
- for word in words:
45
- system_prompt = (
46
- f"Given the following {language} word, create an anki flashcard which has the word, the definition, and an example sentence using that word."
47
- "return the flashcard as each field separated by colons"
48
- )
49
- user_prompt = f"{system_prompt}\n\nText:\n{text}"
50
-
51
- input_ids = tokenizer.apply_chat_template([{"role": "user", "content": user_prompt}], return_tensors="pt").to(model.device)
52
- output_ids = model.generate(input_ids, max_new_tokens=256)
53
- output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
54
-
55
- # Parse response: take last line, split by commas
56
- last_line = output_text.strip().split("\n")[-1]
57
- card = [w.strip() for w in last_line.split(":") if w.strip()]
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)