Baidarkaa commited on
Commit
76c795c
·
verified ·
1 Parent(s): dcb1b6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ TASK = "NER"
6
+ MODEL_NAME = "dslim/bert-base-NER"
7
+ pipe = pipeline(TASK, model=MODEL_NAME)
8
+
9
+ MAX_CHARS = 2000
10
+
11
+ def run(text: str)
12
+ if text is None or not text.strip():
13
+ return "Ошибка: пустой ввод.", None, None
14
+ t0 = time.time()
15
+ try:
16
+ result = pipe(text)
17
+ latency = round((time.time() - t0) * 1000, 1)
18
+ return "OK", result, f"{latency} ms"
19
+ except Exception as e:
20
+ return f"Ошибка: {type(e).__name__}: {e}", None,
21
+ None
22
+
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown(f"""
25
+ # NLP-приложение (Hugging Face Spaces + Gradio)
26
+ **Задача:** {TASK}
27
+ **Модель:** {MODEL_NAME}
28
+ """)
29
+
30
+ inp = gr.Textbox(label="Введите текст", lines=6, placeholder="Скопируйте сюда текст...")
31
+ btn = gr.Button("Обработать")
32
+ status = gr.Textbox(label="Статус")
33
+ out = gr.JSON(label="Результат модели")
34
+ latency = gr.Textbox(label="Время ответа")
35
+
36
+ btn.click(run, inputs=inp, outputs=[status, out, latency])
37
+
38
+ gr.Examples(
39
+ examples=[
40
+ ["I love this product! It works great."],
41
+ ["This is the worst experience ever."],
42
+ ["It's okay, nothing special."]
43
+ ],
44
+ inputs=inp
45
+ )
46
+
47
+ demo.launch()