Spaces:
Running
Running
Added logging
Browse files
app.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
import gradio
|
2 |
-
|
|
|
3 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
4 |
classifier = pipeline("zero-shot-classification",
|
5 |
model="facebook/bart-large-mnli")
|
6 |
|
@@ -27,7 +33,12 @@ def transform_output(res: dict) -> list:
|
|
27 |
)
|
28 |
|
29 |
def clf_text(txt: str | list[str]):
|
|
|
|
|
30 |
res = classifier(txt, categories, multi_label=True)
|
|
|
|
|
|
|
31 |
if isinstance(res, list):
|
32 |
return [ transform_output(dct) for dct in res ]
|
33 |
else:
|
@@ -52,4 +63,5 @@ gradio_interface = gradio.Interface(
|
|
52 |
inputs = "text",
|
53 |
outputs = gradio.JSON()
|
54 |
)
|
|
|
55 |
gradio_interface.launch()
|
|
|
1 |
import gradio
|
2 |
+
import logging
|
3 |
+
import time
|
4 |
from transformers import pipeline
|
5 |
+
|
6 |
+
logger = logging.getLogger()
|
7 |
+
logger.setLevel(logging.DEBUG)
|
8 |
+
logging.debug("Starting logging for gradio_test_001.")
|
9 |
+
|
10 |
classifier = pipeline("zero-shot-classification",
|
11 |
model="facebook/bart-large-mnli")
|
12 |
|
|
|
33 |
)
|
34 |
|
35 |
def clf_text(txt: str | list[str]):
|
36 |
+
logger.debug("Classify: " + repr(txt))
|
37 |
+
t0 = time.time()
|
38 |
res = classifier(txt, categories, multi_label=True)
|
39 |
+
elapsed = time.time() - t0
|
40 |
+
logger.debug(f"Done. {elapsed:.02f}s")
|
41 |
+
logger.debug(f"Result(s):", res)
|
42 |
if isinstance(res, list):
|
43 |
return [ transform_output(dct) for dct in res ]
|
44 |
else:
|
|
|
63 |
inputs = "text",
|
64 |
outputs = gradio.JSON()
|
65 |
)
|
66 |
+
logger.debug("Launch app.")
|
67 |
gradio_interface.launch()
|