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")
|
@@ -13,6 +13,7 @@ fake_news_pipeline = pipeline("text-classification", model="roberta-base-openai-
|
|
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):
|
@@ -75,6 +76,17 @@ 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!",
|
@@ -156,6 +168,13 @@ code_generation_examples = [
|
|
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"):
|
@@ -271,6 +290,21 @@ with gr.Blocks() as demo:
|
|
271 |
examples=code_generation_examples,
|
272 |
examples_per_page=2
|
273 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
# Запускаем интерфейс
|
276 |
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")
|
|
|
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 |
+
code_fix_pipeline = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct")
|
17 |
|
18 |
# Функция для анализа тональности текста
|
19 |
def analyze_sentiment(text):
|
|
|
76 |
result = code_generation_pipeline(prompt, max_length=100, num_return_sequences=1)
|
77 |
return result[0]['generated_text']
|
78 |
|
79 |
+
# Функция для исправления кода
|
80 |
+
def fix_code(error, problem, solution, example):
|
81 |
+
prompt = f"""
|
82 |
+
**Ошибка:** {error}
|
83 |
+
**Проблема:** {problem}
|
84 |
+
**Решение:** {solution}
|
85 |
+
**Пример:** {example}
|
86 |
+
"""
|
87 |
+
result = code_fix_pipeline(prompt, max_length=200, num_return_sequences=1)
|
88 |
+
return result[0]['generated_text']
|
89 |
+
|
90 |
# Примеры текстов для анализа тональности
|
91 |
sentiment_examples = [
|
92 |
"I love programming, it's so much fun!",
|
|
|
168 |
"Generate a SQL query to find all users older than 30."
|
169 |
]
|
170 |
|
171 |
+
# Примеры для исправления кода
|
172 |
+
code_fix_examples = [
|
173 |
+
["SyntaxError: invalid syntax", "Missing colon at the end of the if statement", "Add a colon at the end of the if statement", "if x == 5\n print('Hello')"],
|
174 |
+
["NameError: name 'x' is not defined", "Variable 'x' is not defined before use", "Define the variable 'x' before using it", "print(x)\nx = 10"],
|
175 |
+
["IndentationError: unexpected indent", "Incorrect indentation in the code", "Fix the indentation to match the correct level", "def foo():\n print('Hello')\n print('World')"]
|
176 |
+
]
|
177 |
+
|
178 |
# Создаем интерфейс Gradio с вкладками
|
179 |
with gr.Blocks() as demo:
|
180 |
with gr.Tab("Sentiment Analysis"):
|
|
|
290 |
examples=code_generation_examples,
|
291 |
examples_per_page=2
|
292 |
)
|
293 |
+
with gr.Tab("Code Fix"):
|
294 |
+
gr.Interface(
|
295 |
+
fn=fix_code,
|
296 |
+
inputs=[
|
297 |
+
gr.Textbox(lines=2, placeholder="Ошибка..."),
|
298 |
+
gr.Textbox(lines=2, placeholder="Проблема..."),
|
299 |
+
gr.Textbox(lines=2, placeholder="Решение..."),
|
300 |
+
gr.Textbox(lines=2, placeholder="Пример...")
|
301 |
+
],
|
302 |
+
outputs="text",
|
303 |
+
title="Исправление кода",
|
304 |
+
description="Введите ошибку, проблему, решение и пример, чтобы получить исправленный код.",
|
305 |
+
examples=code_fix_examples,
|
306 |
+
examples_per_page=2
|
307 |
+
)
|
308 |
|
309 |
# Запускаем интерфейс
|
310 |
demo.launch()
|