Spaces:
Sleeping
Sleeping
xsamueljr
commited on
Commit
·
283b87d
1
Parent(s):
22b93fc
extracted examples to a constant and excluded those from telemetry data
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import login, CommitScheduler
|
5 |
|
@@ -26,7 +27,9 @@ async def app_func(text: str, language: str) -> int:
|
|
26 |
raise gr.Error(e)
|
27 |
|
28 |
result = models[request.language].analyze(request.text)
|
29 |
-
|
|
|
|
|
30 |
|
31 |
percentage = round(result.percentage * 100)
|
32 |
percentage = max(percentage, 0)
|
@@ -34,6 +37,14 @@ async def app_func(text: str, language: str) -> int:
|
|
34 |
|
35 |
return percentage
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
demo = gr.Interface(
|
39 |
fn=app_func,
|
@@ -41,7 +52,7 @@ demo = gr.Interface(
|
|
41 |
outputs=gr.Label(num_top_classes=1, label="Probabilidad de phishing"),
|
42 |
title="ConfIA Model Demo",
|
43 |
description="Demo que te permite probar nuestros modelos de forma muy sencilla",
|
44 |
-
examples=
|
45 |
cache_examples=True
|
46 |
)
|
47 |
|
|
|
1 |
import os
|
2 |
|
3 |
+
from consts import EXAMPLES
|
4 |
import gradio as gr
|
5 |
from huggingface_hub import login, CommitScheduler
|
6 |
|
|
|
27 |
raise gr.Error(e)
|
28 |
|
29 |
result = models[request.language].analyze(request.text)
|
30 |
+
|
31 |
+
if not is_request_in_examples(request):
|
32 |
+
telemetry.write_data(DataEntry(text, result))
|
33 |
|
34 |
percentage = round(result.percentage * 100)
|
35 |
percentage = max(percentage, 0)
|
|
|
37 |
|
38 |
return percentage
|
39 |
|
40 |
+
def is_request_in_examples(request: Request) -> bool:
|
41 |
+
for example in EXAMPLES:
|
42 |
+
text = example[0]
|
43 |
+
lang = example[1]
|
44 |
+
if request.text == text and request.language.value == lang:
|
45 |
+
return True
|
46 |
+
return False
|
47 |
+
|
48 |
|
49 |
demo = gr.Interface(
|
50 |
fn=app_func,
|
|
|
52 |
outputs=gr.Label(num_top_classes=1, label="Probabilidad de phishing"),
|
53 |
title="ConfIA Model Demo",
|
54 |
description="Demo que te permite probar nuestros modelos de forma muy sencilla",
|
55 |
+
examples=EXAMPLES,
|
56 |
cache_examples=True
|
57 |
)
|
58 |
|
consts.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from lib.lang import Language
|
2 |
+
|
3 |
+
|
4 |
+
EXAMPLES = [
|
5 |
+
["You have just Woned a free iPhone 16!! FOR FREE!!!", Language.ENGLISH.value],
|
6 |
+
["Podemos tener la segunda entrevista cuando a usted le venga bien", Language.SPANISH.value]
|
7 |
+
]
|