Yaron Koresh commited on
Commit
eb977a1
·
verified ·
1 Parent(s): a6305de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -39,22 +39,17 @@ def translate(text,lang):
39
  if text == "" or lang == "":
40
  return ""
41
 
42
- print(text)
43
- print(lang)
44
-
45
  if len(text) > 38:
46
  raise Exception("Translation Error: Too long text!")
47
 
48
  user_agents = [
49
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
50
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
51
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
52
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
53
  'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
54
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
- query_text = f'Please translate {text} into {lang}'
58
  url = f'https://www.google.com/search?q={query_text}'
59
 
60
  print(url)
@@ -80,7 +75,7 @@ def translate(text,lang):
80
  if trgt_lang == lang:
81
  translated = trgt_text
82
  except:
83
- print(f'Warning: Could not translate "{text}" into {lang}!')
84
 
85
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
86
  print(ret)
@@ -110,9 +105,9 @@ def infer(prompt,prompt2):
110
  else:
111
  _do = f'photographed { prompt_en }, warm dark muted vintage foreground colors, rough texture, dynamic poze, proportional, reasonable, realistic, natural, cold light vivid playful background colors'
112
  if prompt2 == None or prompt2.strip() == "":
113
- _dont = 'blurred, unreasonable, unreal, ugly, deformed, disfigured, poor details, bad anatomy, logos, texts, labels'
114
  else:
115
- _dont = f'{prompt2_en}, {prompt2_en} where in {prompt_en}, labels where in {prompt_en}, blurred, unreasonable, unreal, texts, logos, ugly, deformed, disfigured, poor details, bad anatomy'
116
  image = Piper(_do,_dont).images[0].save(name)
117
  return name
118
 
 
39
  if text == "" or lang == "":
40
  return ""
41
 
 
 
 
42
  if len(text) > 38:
43
  raise Exception("Translation Error: Too long text!")
44
 
45
  user_agents = [
 
 
46
  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
47
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
48
  'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
49
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
50
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
51
  ]
52
+ query_text = f'Please translate {re.sub('^-|-$','',text.replace("","-").replace("- -"," ")).strip()}, into {lang}'
53
  url = f'https://www.google.com/search?q={query_text}'
54
 
55
  print(url)
 
75
  if trgt_lang == lang:
76
  translated = trgt_text
77
  except:
78
+ print(f'Translation Warning: Failed To Translate!')
79
 
80
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
81
  print(ret)
 
105
  else:
106
  _do = f'photographed { prompt_en }, warm dark muted vintage foreground colors, rough texture, dynamic poze, proportional, reasonable, realistic, natural, cold light vivid playful background colors'
107
  if prompt2 == None or prompt2.strip() == "":
108
+ _dont = 'unreasonable, unreal, ugly, deformed, disfigured, poor details, bad anatomy, logos, texts, labels'
109
  else:
110
+ _dont = f'{prompt2_en}, {prompt2_en} where in {prompt_en}, labels where in {prompt_en}, unreasonable, unreal, texts, logos, ugly, deformed, disfigured, poor details, bad anatomy'
111
  image = Piper(_do,_dont).images[0].save(name)
112
  return name
113