khaledeng15 commited on
Commit
2383d45
โ€ข
1 Parent(s): 1f01f64

add translation

Browse files
__pycache__/app.cpython-312.pyc CHANGED
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
 
__pycache__/home.cpython-312.pyc CHANGED
Binary files a/__pycache__/home.cpython-312.pyc and b/__pycache__/home.cpython-312.pyc differ
 
app.py CHANGED
@@ -2,6 +2,8 @@
2
  # https://gist.github.com/brandon8863/3ee552870a066eba463d37f0b39a547a
3
  import gradio as gr
4
  import webpages.blip_image_captioning as blip_image_captioning
 
 
5
  import home as home
6
 
7
 
@@ -15,6 +17,8 @@ def routs():
15
  with gr.Column() as result:
16
  gr.Button("๐Ÿ  Home", link="/?page=home")
17
  gr.Button("๐Ÿ‘€ Find out what in the photo", link="/?page=blip_image_captioning")
 
 
18
 
19
  def handePages(local_state):
20
  with gr.Column(scale=30):
@@ -29,6 +33,8 @@ def handePages(local_state):
29
  return home.get(), local_state
30
  elif local_state == "blip_image_captioning":
31
  return blip_image_captioning.get(local_state), local_state
 
 
32
  else:
33
  return (
34
  home.get_not_found_page(local_state),
 
2
  # https://gist.github.com/brandon8863/3ee552870a066eba463d37f0b39a547a
3
  import gradio as gr
4
  import webpages.blip_image_captioning as blip_image_captioning
5
+ import webpages.text_generation as text_generation
6
+
7
  import home as home
8
 
9
 
 
17
  with gr.Column() as result:
18
  gr.Button("๐Ÿ  Home", link="/?page=home")
19
  gr.Button("๐Ÿ‘€ Find out what in the photo", link="/?page=blip_image_captioning")
20
+ gr.Button("๐Ÿ“ Text Generation", link="/?page=text_generation")
21
+
22
 
23
  def handePages(local_state):
24
  with gr.Column(scale=30):
 
33
  return home.get(), local_state
34
  elif local_state == "blip_image_captioning":
35
  return blip_image_captioning.get(local_state), local_state
36
+ elif local_state == "text_generation":
37
+ return text_generation.get(local_state), local_state
38
  else:
39
  return (
40
  home.get_not_found_page(local_state),
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ text,output,flag,username,timestamp
2
+ how are you,ูƒูŠู ุญุงู„ูƒ,,,2024-09-16 23:42:11.972065
webpages/__pycache__/blip_image_captioning.cpython-312.pyc CHANGED
Binary files a/webpages/__pycache__/blip_image_captioning.cpython-312.pyc and b/webpages/__pycache__/blip_image_captioning.cpython-312.pyc differ
 
webpages/__pycache__/text_generation.cpython-312.pyc ADDED
Binary file (1.54 kB). View file
 
webpages/text_generation.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a pipeline as a high-level helper
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+ import torch
5
+ import gc
6
+
7
+ translator = pipeline("translation", model="facebook/nllb-200-distilled-600M", torch_dtype=torch.bfloat16)
8
+
9
+ lang_list = ["English", "ุนุฑุจู‰", "French"]
10
+ lang_code = {"English":"eng_Latn", "ุนุฑุจู‰" : "arz_Arab", "French" : "fra_Latn"}
11
+
12
+ from_lang="eng_Latn"
13
+ to_lang="arz_Arab"
14
+
15
+ def claer():
16
+ del translator
17
+ gc.collect()
18
+
19
+ def transalate(text) :
20
+ # claer()
21
+ text_translated = translator(text,
22
+ src_lang=from_lang,
23
+ tgt_lang=to_lang)
24
+ print(to_lang)
25
+
26
+ return text_translated[0]['translation_text']
27
+
28
+ def form():
29
+ return gr.Interface(transalate,
30
+ inputs="textbox",
31
+ outputs="text")
32
+ def rs_change_from(c):
33
+ from_lang = lang_code[c]
34
+ print(from_lang)
35
+
36
+ def rs_change_to(c):
37
+ to_lang = lang_code[c]
38
+ print(to_lang)
39
+
40
+ def get(local_state):
41
+ with gr.Column() as result:
42
+ gr.HTML("<br/>")
43
+ gr.Markdown("## Text Generation")
44
+ dropdownFrom = gr.Dropdown(
45
+ lang_code, label="Transalte From", info="Will add more later!"
46
+ )
47
+ dropdownFrom.select(rs_change_from,dropdownFrom)
48
+ dropdownTo = gr.Dropdown(
49
+ lang_list, label="Transalte To", info="Will add more later!"
50
+ )
51
+ dropdownTo.select(rs_change_to,dropdownTo)
52
+
53
+ form()
54
+ gr.HTML("<br/><br/><br/><br/>")
55
+
56
+ return result
57
+
58
+
59
+
60
+
61
+
62
+
63
+ # - Afrikaans: afr_Latn
64
+ # - Chinese: zho_Hans
65
+ # - Egyptian Arabic: arz_Arab
66
+ # - French: fra_Latn
67
+ # - German: deu_Latn
68
+ # - Greek: ell_Grek
69
+ # - Hindi: hin_Deva
70
+ # - Indonesian: ind_Latn
71
+ # - Italian: ita_Latn
72
+ # - Japanese: jpn_Jpan
73
+ # - Korean: kor_Hang
74
+ # - Persian: pes_Arab
75
+ # - Portuguese: por_Latn
76
+ # - Russian: rus_Cyrl
77
+ # - Spanish: spa_Latn
78
+ # - Swahili: swh_Latn
79
+ # - Thai: tha_Thai
80
+ # - Turkish: tur_Latn
81
+ # - Vietnamese: vie_Latn
82
+ # - Zulu: zul_Latn