Spaces:
Runtime error
Runtime error
freemt
commited on
Commit
·
508e2de
1
Parent(s):
79720de
Update time.tzset()
Browse files- app.py +26 -9
- flagged/component 2/0.png +0 -0
- flagged/log.csv +2 -0
- gradio_queue.db +0 -0
app.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
"""See https://huggingface.co/spaces/Gradio-Blocks/Story-to-video/blob/main/app.py."""
|
2 |
import base64
|
3 |
import io
|
|
|
4 |
import re
|
|
|
5 |
from random import choice
|
6 |
|
7 |
import gradio as gr
|
@@ -9,8 +11,9 @@ import translators as ts
|
|
9 |
from fastlid import fastlid
|
10 |
from logzero import logger
|
11 |
from PIL import Image # opencv-python
|
|
|
12 |
from tenacity import retry
|
13 |
-
from tenacity.stop import stop_after_attempt, stop_after_delay
|
14 |
|
15 |
# from PIL import Image
|
16 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
@@ -18,11 +21,19 @@ from tenacity.stop import stop_after_attempt, stop_after_delay
|
|
18 |
# import torch
|
19 |
|
20 |
image_gen = gr.Interface.load("spaces/multimodalart/latentdiffusion")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
examples_ = [
|
23 |
-
"蓝色的夜,森林中好多萤火虫",
|
24 |
"黑云压城城欲摧 ,甲光向日金鳞开。",
|
25 |
"黄金在河里流淌,宝石遍地,空中铺满巨大的彩虹。",
|
|
|
26 |
"季姬寂,集鸡,鸡即棘鸡。棘鸡饥叽,季姬及箕稷济鸡。",
|
27 |
"an apple",
|
28 |
"a cat",
|
@@ -31,10 +42,15 @@ examples_ = [
|
|
31 |
]
|
32 |
|
33 |
|
34 |
-
@retry(stop=(stop_after_delay(10) | stop_after_attempt(5)))
|
|
|
35 |
def tr_(text: str) -> str:
|
36 |
-
"""Wrap [ts.deepl, ts.
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
try:
|
39 |
res = tr(text)
|
40 |
logger.info(" api used: %s", tr.__name__)
|
@@ -44,6 +60,7 @@ def tr_(text: str) -> str:
|
|
44 |
continue
|
45 |
else:
|
46 |
res = "Something is probably wong, ping dev to fix it if you like."
|
|
|
47 |
return res
|
48 |
|
49 |
|
@@ -53,20 +70,20 @@ def generate_images(phrase: str, steps: int = 125):
|
|
53 |
|
54 |
generated_text = phrase
|
55 |
detected = "en"
|
56 |
-
|
57 |
try:
|
58 |
detected = fastlid(phrase)[0]
|
59 |
except Exception as exc:
|
60 |
logger.error(exc)
|
61 |
|
62 |
-
#
|
63 |
if len(phrase) < 10 and re.search(r"[一-龟]+", phrase):
|
64 |
detected = "zh"
|
65 |
|
66 |
if detected not in ["en"]:
|
67 |
try:
|
68 |
generated_text = tr_(phrase)
|
69 |
-
|
70 |
except Exception as exc:
|
71 |
logger.error(exc)
|
72 |
return None, f"{phrase:}, errors: {str(exc)}"
|
@@ -90,7 +107,7 @@ def generate_images(phrase: str, steps: int = 125):
|
|
90 |
# generated_images = []
|
91 |
|
92 |
img = None
|
93 |
-
err_msg = f"{phrase} {
|
94 |
for image in image_bytes[1]:
|
95 |
image_str = image[0]
|
96 |
try:
|
|
|
1 |
"""See https://huggingface.co/spaces/Gradio-Blocks/Story-to-video/blob/main/app.py."""
|
2 |
import base64
|
3 |
import io
|
4 |
+
import os
|
5 |
import re
|
6 |
+
import time
|
7 |
from random import choice
|
8 |
|
9 |
import gradio as gr
|
|
|
11 |
from fastlid import fastlid
|
12 |
from logzero import logger
|
13 |
from PIL import Image # opencv-python
|
14 |
+
from random import choices
|
15 |
from tenacity import retry
|
16 |
+
from tenacity.stop import stop_after_attempt # , stop_after_delay
|
17 |
|
18 |
# from PIL import Image
|
19 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
|
|
21 |
# import torch
|
22 |
|
23 |
image_gen = gr.Interface.load("spaces/multimodalart/latentdiffusion")
|
24 |
+
# image_gen = gr.Interface.load("huggingface/multimodalart/latentdiffusion")
|
25 |
+
|
26 |
+
os.environ["TZ"] = "Asia/Shanghai"
|
27 |
+
try:
|
28 |
+
time.tzset()
|
29 |
+
except Exception:
|
30 |
+
... # Windows
|
31 |
+
|
32 |
|
33 |
examples_ = [
|
|
|
34 |
"黑云压城城欲摧 ,甲光向日金鳞开。",
|
35 |
"黄金在河里流淌,宝石遍地,空中铺满巨大的彩虹。",
|
36 |
+
"蓝色的夜,森林中好多萤火虫",
|
37 |
"季姬寂,集鸡,鸡即棘鸡。棘鸡饥叽,季姬及箕稷济鸡。",
|
38 |
"an apple",
|
39 |
"a cat",
|
|
|
42 |
]
|
43 |
|
44 |
|
45 |
+
# @retry(stop=(stop_after_delay(10) | stop_after_attempt(5)))
|
46 |
+
@retry(stop=stop_after_attempt(5))
|
47 |
def tr_(text: str) -> str:
|
48 |
+
"""Wrap [ts.deepl, ts.baidu, ts.google] with tenacity.
|
49 |
+
|
50 |
+
not working: sogou; ?tencent
|
51 |
+
"""
|
52 |
+
cand = [ts.baidu, ts.youdao, ts.google]
|
53 |
+
for tr in [ts.deepl] + choices(cand, k=len(cand)):
|
54 |
try:
|
55 |
res = tr(text)
|
56 |
logger.info(" api used: %s", tr.__name__)
|
|
|
60 |
continue
|
61 |
else:
|
62 |
res = "Something is probably wong, ping dev to fix it if you like."
|
63 |
+
|
64 |
return res
|
65 |
|
66 |
|
|
|
70 |
|
71 |
generated_text = phrase
|
72 |
detected = "en"
|
73 |
+
extra_info = ""
|
74 |
try:
|
75 |
detected = fastlid(phrase)[0]
|
76 |
except Exception as exc:
|
77 |
logger.error(exc)
|
78 |
|
79 |
+
# safeguard short Chinese phrases
|
80 |
if len(phrase) < 10 and re.search(r"[一-龟]+", phrase):
|
81 |
detected = "zh"
|
82 |
|
83 |
if detected not in ["en"]:
|
84 |
try:
|
85 |
generated_text = tr_(phrase)
|
86 |
+
extra_info = f"({tr_.api_used}: {generated_text})"
|
87 |
except Exception as exc:
|
88 |
logger.error(exc)
|
89 |
return None, f"{phrase:}, errors: {str(exc)}"
|
|
|
107 |
# generated_images = []
|
108 |
|
109 |
img = None
|
110 |
+
err_msg = f"{phrase} {extra_info}"
|
111 |
for image in image_bytes[1]:
|
112 |
image_str = image[0]
|
113 |
try:
|
flagged/component 2/0.png
ADDED
![]() |
flagged/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
'phrase','steps','component 2','phrase','flag','username','timestamp'
|
2 |
+
'黑云压城城欲摧 ,甲光向日金鳞开。',125,'component 2/0.png','黑云压城城欲摧 ,甲光向日金鳞开。 (sogou_api)','','','2022-07-20 06:24:49.026071'
|
gradio_queue.db
DELETED
File without changes
|