Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -35,14 +35,14 @@ def translate(text,lang):
|
|
35 |
'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',
|
36 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
37 |
]
|
38 |
-
resp = requests.
|
39 |
-
url = f"https://
|
40 |
headers = {
|
41 |
'User-Agent': random.choice(user_agents)
|
42 |
}
|
43 |
)
|
44 |
-
translated = fromstring(resp.content).xpath(
|
45 |
-
return translated
|
46 |
|
47 |
def generate_random_string(length):
|
48 |
characters = string.ascii_letters + string.digits
|
@@ -51,7 +51,7 @@ def generate_random_string(length):
|
|
51 |
@spaces.GPU(duration=20)
|
52 |
def infer(prompt):
|
53 |
name = generate_random_string(12)+".png"
|
54 |
-
english_prompt = 'The "
|
55 |
print(f'Final prompt: {english_prompt}')
|
56 |
image = pipe(english_prompt).images[0].save(name)
|
57 |
return name
|
|
|
35 |
'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',
|
36 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
37 |
]
|
38 |
+
resp = requests.post(
|
39 |
+
url = f"https://dictionary.cambridge.org/translate/?languageFrom=auto&txtTrans={text}&languageTo={lang}",
|
40 |
headers = {
|
41 |
'User-Agent': random.choice(user_agents)
|
42 |
}
|
43 |
)
|
44 |
+
translated = fromstring(resp.content).xpath('//div[@id="translate-tool__result"')[0].text().strip()
|
45 |
+
return re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
|
46 |
|
47 |
def generate_random_string(length):
|
48 |
characters = string.ascii_letters + string.digits
|
|
|
51 |
@spaces.GPU(duration=20)
|
52 |
def infer(prompt):
|
53 |
name = generate_random_string(12)+".png"
|
54 |
+
english_prompt = f'The "{translate(prompt,"english")}" authentically labels-free genuine accurate:'
|
55 |
print(f'Final prompt: {english_prompt}')
|
56 |
image = pipe(english_prompt).images[0].save(name)
|
57 |
return name
|