Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения
|
5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
summarization_pipeline = pipeline("summarization")
|
7 |
image_captioning_pipeline = pipeline("image-to-text")
|
@@ -10,6 +10,7 @@ translation_pipeline = pipeline("translation_en_to_ru", model="Helsinki-NLP/opus
|
|
10 |
emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
|
11 |
code_completion_pipeline = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
|
12 |
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
|
|
|
13 |
|
14 |
# Функция для анализа тональности текста
|
15 |
def analyze_sentiment(text):
|
@@ -51,6 +52,14 @@ def detect_fake_news(text):
|
|
51 |
result = fake_news_pipeline(text)[0]
|
52 |
return f"Label: {result['label']}, Confidence: {result['score']:.4f}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Примеры текстов для анализа тональности
|
55 |
sentiment_examples = [
|
56 |
"I love programming, it's so much fun!",
|
@@ -111,6 +120,13 @@ fake_news_examples = [
|
|
111 |
"Scientists have discovered a new planet in our solar system that is inhabited by aliens."
|
112 |
]
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
# Создаем интерфейс Gradio с вкладками
|
115 |
with gr.Blocks() as demo:
|
116 |
with gr.Tab("Sentiment Analysis"):
|
@@ -196,6 +212,16 @@ with gr.Blocks() as demo:
|
|
196 |
examples=fake_news_examples,
|
197 |
examples_per_page=2
|
198 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
# Запускаем интерфейс
|
201 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения кода, определения фейковых новостей и NER
|
5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
summarization_pipeline = pipeline("summarization")
|
7 |
image_captioning_pipeline = pipeline("image-to-text")
|
|
|
10 |
emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
|
11 |
code_completion_pipeline = pipeline("text-generation", model="Salesforce/codegen-350M-mono")
|
12 |
fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-detector")
|
13 |
+
ner_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", grouped_entities=True)
|
14 |
|
15 |
# Функция для анализа тональности текста
|
16 |
def analyze_sentiment(text):
|
|
|
52 |
result = fake_news_pipeline(text)[0]
|
53 |
return f"Label: {result['label']}, Confidence: {result['score']:.4f}"
|
54 |
|
55 |
+
# Функция для распознавания именованных сущностей (NER)
|
56 |
+
def recognize_entities(text):
|
57 |
+
result = ner_pipeline(text)
|
58 |
+
entities = []
|
59 |
+
for entity in result:
|
60 |
+
entities.append(f"Entity: {entity['word']}, Label: {entity['entity_group']}, Confidence: {entity['score']:.4f}")
|
61 |
+
return "\n".join(entities)
|
62 |
+
|
63 |
# Примеры текстов для анализа тональности
|
64 |
sentiment_examples = [
|
65 |
"I love programming, it's so much fun!",
|
|
|
120 |
"Scientists have discovered a new planet in our solar system that is inhabited by aliens."
|
121 |
]
|
122 |
|
123 |
+
# Примеры текстов для распознавания именованных сущностей (NER)
|
124 |
+
ner_examples = [
|
125 |
+
"My name is John Doe and I live in New York.",
|
126 |
+
"Apple is looking at buying a startup in the UK for $1 billion.",
|
127 |
+
"Elon Musk is the CEO of Tesla and SpaceX."
|
128 |
+
]
|
129 |
+
|
130 |
# Создаем интерфейс Gradio с вкладками
|
131 |
with gr.Blocks() as demo:
|
132 |
with gr.Tab("Sentiment Analysis"):
|
|
|
212 |
examples=fake_news_examples,
|
213 |
examples_per_page=2
|
214 |
)
|
215 |
+
with gr.Tab("Named Entity Recognition (NER)"):
|
216 |
+
gr.Interface(
|
217 |
+
fn=recognize_entities,
|
218 |
+
inputs=gr.Textbox(lines=5, placeholder="Введите текст для распознавания сущностей..."),
|
219 |
+
outputs="text",
|
220 |
+
title="Распознавание именованных сущностей (NER)",
|
221 |
+
description="Введите текст, чтобы извлечь из него именованные сущности.",
|
222 |
+
examples=ner_examples,
|
223 |
+
examples_per_page=2
|
224 |
+
)
|
225 |
|
226 |
# Запускаем интерфейс
|
227 |
demo.launch()
|