EmadSalem commited on
Commit
2505ec2
1 Parent(s): 9f45895

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -16,6 +16,41 @@ session_token = os.environ.get('SessionToken')
16
 
17
 
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  title="بسم الله الرحمن الرحيم"
21
  description="ERNIE-ViLG model, which supports text-to-image task."
@@ -134,7 +169,6 @@ with block:
134
  """
135
  )
136
 
137
- description="ERNIE-ViLG model, which supports text-to-image task."
138
 
139
 
140
 
 
16
 
17
 
18
 
19
+ count = 0
20
+
21
+ def translate_language(text_prompts):
22
+ global count
23
+ try:
24
+ count += 1
25
+ tips_text = None
26
+ language_code = language_recognition_model.recognize(text_prompts)
27
+ if language_code != 'zh':
28
+ text_prompts = language_translation_model.translate(text_prompts, language_code, 'zh')
29
+ except Exception as e:
30
+ error_text = str(e)
31
+ return {status_text:error_text, language_tips_text:gr.update(visible=False)}
32
+ if language_code in tips:
33
+ tips_text = tips[language_code]
34
+ else:
35
+ tips_text = tips['en']
36
+ if language_code == 'zh':
37
+ return {language_tips_text:gr.update(visible=False), translated_language:text_prompts, trigger_component: gr.update(value=count, visible=False)}
38
+ else:
39
+ return {language_tips_text:gr.update(visible=True, value=tips_text), translated_language:text_prompts, trigger_component: gr.update(value=count, visible=False)}
40
+
41
+
42
+ def inference(text_prompts, style_indx):
43
+ try:
44
+ model.token = model._apply_token(model.ak, model.sk)
45
+ style = style_list[style_indx]
46
+ results = model.generate_image(
47
+ text_prompts=text_prompts, style=style, visualization=False, topk=4)
48
+ except Exception as e:
49
+ error_text = str(e)
50
+ return {status_text:error_text, gallery:None}
51
+ return {status_text:'Success', gallery:results[:4]}
52
+
53
+
54
 
55
  title="بسم الله الرحمن الرحيم"
56
  description="ERNIE-ViLG model, which supports text-to-image task."
 
169
  """
170
  )
171
 
 
172
 
173
 
174