Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
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")
|
8 |
qa_pipeline = pipeline("question-answering")
|
|
|
9 |
|
10 |
# Функция для анализа тональности текста
|
11 |
def analyze_sentiment(text):
|
@@ -27,6 +28,11 @@ def answer_question(context, question):
|
|
27 |
result = qa_pipeline(question=question, context=context)
|
28 |
return f"Answer: {result['answer']}, Confidence: {result['score']:.4f}"
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
# Примеры текстов для анализа тональности
|
31 |
sentiment_examples = [
|
32 |
"I love programming, it's so much fun!",
|
@@ -57,6 +63,12 @@ qa_examples = [
|
|
57 |
["Artificial intelligence is transforming industries by automating tasks and providing insights from large datasets.", "How is AI transforming industries?"]
|
58 |
]
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
# Создаем интерфейс Gradio с вкладками
|
61 |
with gr.Blocks() as demo:
|
62 |
with gr.Tab("Sentiment Analysis"):
|
@@ -67,7 +79,7 @@ with gr.Blocks() as demo:
|
|
67 |
title="Анализ тональности текста",
|
68 |
description="Введите текст, чтобы определить его тональность.",
|
69 |
examples=sentiment_examples,
|
70 |
-
examples_per_page=
|
71 |
)
|
72 |
with gr.Tab("Text Summarization"):
|
73 |
gr.Interface(
|
@@ -77,7 +89,7 @@ with gr.Blocks() as demo:
|
|
77 |
title="Суммаризация текста",
|
78 |
description="Введите текст, чтобы получить его краткое содержание.",
|
79 |
examples=summarization_examples,
|
80 |
-
examples_per_page=
|
81 |
)
|
82 |
with gr.Tab("Image Captioning"):
|
83 |
gr.Interface(
|
@@ -87,7 +99,7 @@ with gr.Blocks() as demo:
|
|
87 |
title="Генерация подписи к изображению",
|
88 |
description="Загрузите изображение, чтобы сгенерировать его описание.",
|
89 |
examples=image_examples,
|
90 |
-
examples_per_page=
|
91 |
)
|
92 |
with gr.Tab("Question Answering"):
|
93 |
gr.Interface(
|
@@ -100,7 +112,17 @@ with gr.Blocks() as demo:
|
|
100 |
title="Ответы на вопросы",
|
101 |
description="Введите контекст и вопрос, чтобы получить ответ.",
|
102 |
examples=qa_examples,
|
103 |
-
examples_per_page=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
)
|
105 |
|
106 |
# Запускаем интерфейс
|
|
|
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")
|
8 |
qa_pipeline = pipeline("question-answering")
|
9 |
+
speech_to_text_pipeline = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
10 |
|
11 |
# Функция для анализа тональности текста
|
12 |
def analyze_sentiment(text):
|
|
|
28 |
result = qa_pipeline(question=question, context=context)
|
29 |
return f"Answer: {result['answer']}, Confidence: {result['score']:.4f}"
|
30 |
|
31 |
+
# Функция для расшифровки аудио в текст
|
32 |
+
def transcribe_audio(audio):
|
33 |
+
result = speech_to_text_pipeline(audio)
|
34 |
+
return result['text']
|
35 |
+
|
36 |
# Примеры текстов для анализа тональности
|
37 |
sentiment_examples = [
|
38 |
"I love programming, it's so much fun!",
|
|
|
63 |
["Artificial intelligence is transforming industries by automating tasks and providing insights from large datasets.", "How is AI transforming industries?"]
|
64 |
]
|
65 |
|
66 |
+
# Примеры аудио для расшифровки
|
67 |
+
audio_examples = [
|
68 |
+
"https://lazypy.ro/tts/assets/audio/StreamElements_Nicole_5c029bf08a515afb40579f0cd0c028bf.mp3", # Пример 1
|
69 |
+
"https://lazypy.ro/tts/assets/audio/Bing_en-US-EricNeural_e2ca58109fc0206fb0d201689ca2bc8f.mp3" # Пример 2
|
70 |
+
]
|
71 |
+
|
72 |
# Создаем интерфейс Gradio с вкладками
|
73 |
with gr.Blocks() as demo:
|
74 |
with gr.Tab("Sentiment Analysis"):
|
|
|
79 |
title="Анализ тональности текста",
|
80 |
description="Введите текст, чтобы определить его тональность.",
|
81 |
examples=sentiment_examples,
|
82 |
+
examples_per_page=3
|
83 |
)
|
84 |
with gr.Tab("Text Summarization"):
|
85 |
gr.Interface(
|
|
|
89 |
title="Суммаризация текста",
|
90 |
description="Введите текст, чтобы получить его краткое содержание.",
|
91 |
examples=summarization_examples,
|
92 |
+
examples_per_page=2
|
93 |
)
|
94 |
with gr.Tab("Image Captioning"):
|
95 |
gr.Interface(
|
|
|
99 |
title="Генерация подписи к изображению",
|
100 |
description="Загрузите изображение, чтобы сгенерировать его описание.",
|
101 |
examples=image_examples,
|
102 |
+
examples_per_page=2
|
103 |
)
|
104 |
with gr.Tab("Question Answering"):
|
105 |
gr.Interface(
|
|
|
112 |
title="Ответы на вопросы",
|
113 |
description="Введите контекст и вопрос, чтобы получить ответ.",
|
114 |
examples=qa_examples,
|
115 |
+
examples_per_page=2
|
116 |
+
)
|
117 |
+
with gr.Tab("Speech-to-Text Transcription"):
|
118 |
+
gr.Interface(
|
119 |
+
fn=transcribe_audio,
|
120 |
+
inputs=gr.Audio(type="filepath", label="Загрузите аудиофайл"),
|
121 |
+
outputs="text",
|
122 |
+
title="Расшифровка аудио в текст",
|
123 |
+
description="Загрузите аудиофайл, чтобы получить его текстовую расшифровку.",
|
124 |
+
examples=audio_examples,
|
125 |
+
examples_per_page=2
|
126 |
)
|
127 |
|
128 |
# Запускаем интерфейс
|