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 |
-
# Загружаем модели для анализа тональности, суммаризации текста, генерации подписей к изображениям, ответов на вопросы, перевода текста, определения эмоций, автодополнения кода, определения фейковых новостей, NER и
|
| 5 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
summarization_pipeline = pipeline("summarization")
|
| 7 |
image_captioning_pipeline = pipeline("image-to-text")
|
|
@@ -12,6 +12,7 @@ code_completion_pipeline = pipeline("text-generation", model="Salesforce/codegen
|
|
| 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 |
image_classification_pipeline = pipeline("image-classification", model="google/vit-base-patch16-224")
|
|
|
|
| 15 |
|
| 16 |
# Функция для анализа тональности текста
|
| 17 |
def analyze_sentiment(text):
|
|
@@ -69,6 +70,11 @@ def classify_image(image):
|
|
| 69 |
classifications.append(f"Label: {item['label']}, Confidence: {item['score']:.4f}")
|
| 70 |
return "\n".join(classifications)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
# Примеры текстов для анализа тональности
|
| 73 |
sentiment_examples = [
|
| 74 |
"I love programming, it's so much fun!",
|
|
@@ -143,6 +149,13 @@ classification_examples = [
|
|
| 143 |
"https://get.wallhere.com/photo/sea-bay-water-beach-coast-swimming-pool-resort-island-lagoon-Caribbean-vacation-estate-leisure-ocean-tropics-2560x1440-px-geographical-feature-atoll-554636.jpg" # Пример 3
|
| 144 |
]
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
# Создаем интерфейс Gradio с вкладками
|
| 147 |
with gr.Blocks() as demo:
|
| 148 |
with gr.Tab("Sentiment Analysis"):
|
|
@@ -248,6 +261,16 @@ with gr.Blocks() as demo:
|
|
| 248 |
examples=classification_examples,
|
| 249 |
examples_per_page=2
|
| 250 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
# Запускаем интерфейс
|
| 253 |
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")
|
|
|
|
| 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 |
image_classification_pipeline = pipeline("image-classification", model="google/vit-base-patch16-224")
|
| 15 |
+
code_generation_pipeline = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct")
|
| 16 |
|
| 17 |
# Функция для анализа тональности текста
|
| 18 |
def analyze_sentiment(text):
|
|
|
|
| 70 |
classifications.append(f"Label: {item['label']}, Confidence: {item['score']:.4f}")
|
| 71 |
return "\n".join(classifications)
|
| 72 |
|
| 73 |
+
# Функция для генерации кода по запросу
|
| 74 |
+
def generate_code(prompt):
|
| 75 |
+
result = code_generation_pipeline(prompt, max_length=100, num_return_sequences=1)
|
| 76 |
+
return result[0]['generated_text']
|
| 77 |
+
|
| 78 |
# Примеры текстов для анализа тональности
|
| 79 |
sentiment_examples = [
|
| 80 |
"I love programming, it's so much fun!",
|
|
|
|
| 149 |
"https://get.wallhere.com/photo/sea-bay-water-beach-coast-swimming-pool-resort-island-lagoon-Caribbean-vacation-estate-leisure-ocean-tropics-2560x1440-px-geographical-feature-atoll-554636.jpg" # Пример 3
|
| 150 |
]
|
| 151 |
|
| 152 |
+
# Примеры запросов для генерации кода
|
| 153 |
+
code_generation_examples = [
|
| 154 |
+
"Write a Python function to calculate the factorial of a number.",
|
| 155 |
+
"Create a JavaScript function to reverse a string.",
|
| 156 |
+
"Generate a SQL query to find all users older than 30."
|
| 157 |
+
]
|
| 158 |
+
|
| 159 |
# Создаем интерфейс Gradio с вкладками
|
| 160 |
with gr.Blocks() as demo:
|
| 161 |
with gr.Tab("Sentiment Analysis"):
|
|
|
|
| 261 |
examples=classification_examples,
|
| 262 |
examples_per_page=2
|
| 263 |
)
|
| 264 |
+
with gr.Tab("Code Generation"):
|
| 265 |
+
gr.Interface(
|
| 266 |
+
fn=generate_code,
|
| 267 |
+
inputs=gr.Textbox(lines=5, placeholder="Введите запрос для генерации кода..."),
|
| 268 |
+
outputs="text",
|
| 269 |
+
title="Генерация кода по запросу",
|
| 270 |
+
description="Введите текстовый запрос, чтобы сгенерировать код.",
|
| 271 |
+
examples=code_generation_examples,
|
| 272 |
+
examples_per_page=2
|
| 273 |
+
)
|
| 274 |
|
| 275 |
# Запускаем интерфейс
|
| 276 |
demo.launch()
|