guymorlan commited on
Commit
c225265
·
1 Parent(s): 236d4de

Create app.y

Browse files
Files changed (1) hide show
  1. app.y +49 -0
app.y ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the model as a translation pipeline
5
+ translator = pipeline("translation_en_to_he", model="guymorlan/LostInTranslation")
6
+ description_text="<div style='direction: rtl;'>הכניסו שם של סרט באנגלית כדי לשבש אותו ללא היכ.. כלומר לתרגם אותו לעברית 😈</div>"
7
+
8
+ explanation = """
9
+ <div dir='rtl'>
10
+ <p>נוצר על ידי <a href="mailto:[email protected]">גיא מור-לן</a>.</p>
11
+
12
+ <h3>שיטות פיענוח (Decoding Methods)</h3>
13
+ <p>שיטת הפיענוח קובעת כיצד מחוללים טקסט באמצעות מודל גנרטיבי. יש הרבה שיטות, אבל כאן בחרתי בשתי שיטות נפוצות והגדרתי אותן באופן שיוביל לתרגומים מגוונים יחסית.</p>
14
+
15
+ <h4>חיפוש אלומה (Beam Search)</h4>
16
+ <p>Beam search is performed with 20 beams, 5 beam groups, and a diversity penalty of 10.0 to induce more diverse translations.</p>
17
+
18
+ <h4>דגימה (Sampling)</h4>
19
+ <p>Nucleus sampling is performed with a top-p of 0.5 and a temperature of 1.8. This method generates wilder translations, but also more nonsense.</p>
20
+ </div>
21
+ """
22
+
23
+ def translate(title, method):
24
+ if "אלומה" in method:
25
+ # Beam search
26
+ translations = translator(title, num_return_sequences=10, num_beams=20, num_beam_groups=5, diversity_penalty=10.0)
27
+ else:
28
+ # Sampling
29
+ translations = translator(title, num_return_sequences=10, do_sample=True, top_k=0, top_p=0.5, temperature=1.8)
30
+
31
+ # Extract just the translated text
32
+ translations_text = [t['translation_text'] for t in translations]
33
+ # Convert list of translations to a HTML string with rtl text direction
34
+ translations_html = "<div dir='rtl'><ol>" + "".join(f"<li>{t}</li>" for t in translations_text) + "</ol></div>"
35
+ return translations_html
36
+
37
+ # Define Gradio interface
38
+ iface = gr.Interface(
39
+ fn=translate,
40
+ inputs=[gr.inputs.Textbox(lines=1, label="כותר", placeholder="Batman's Gun"), gr.Radio(["⚡ חיפוש אלומה", "💥 דגימה"], value="⚡ חיפוש אלומה", label="שיטת פיענוח", info="אם אתם רוצים להתפרע, תבחרו ב-💥 דגימה. מומלץ לנסות את שתי השיטות.")],
41
+ outputs=gr.outputs.HTML(label="Translated Titles"),
42
+ title="🎬🔄💩 Lost In Translation",
43
+ description=description_text,
44
+ allow_flagging='never',
45
+ examples=[["Batman's Gun", "דגימה"], ["Once Upon A Time in Hollywood", "חיפוש אלומה"]],
46
+ article=explanation)
47
+
48
+ # Launch the interface
49
+ iface.launch()