Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Загрузка модели для генерации текста
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
+
|
7 |
+
# Функция для генерации текста по промпту
|
8 |
+
def generate_text(prompt):
|
9 |
+
output = generator(prompt, max_length=100)[0]['generated_text']
|
10 |
+
return output
|
11 |
+
|
12 |
+
# CSS стили для приложения
|
13 |
+
css = """
|
14 |
+
#generate {
|
15 |
+
width: 100%;
|
16 |
+
background: #e253dd !important;
|
17 |
+
border: none;
|
18 |
+
border-radius: 50px;
|
19 |
+
outline: none !important;
|
20 |
+
color: white;
|
21 |
+
}
|
22 |
+
#generate:hover {
|
23 |
+
background: #de6bda !important;
|
24 |
+
outline: none !important;
|
25 |
+
color: #fff;
|
26 |
+
}
|
27 |
+
#image_output {
|
28 |
+
display: flex;
|
29 |
+
justify-content: center;
|
30 |
+
}
|
31 |
+
footer {visibility: hidden !important;}
|
32 |
+
#image_output {
|
33 |
+
height: 100% !important;
|
34 |
+
}
|
35 |
+
"""
|
36 |
+
|
37 |
+
# Создание интерфейса Gradio
|
38 |
+
with gr.Blocks(css=css) as demo:
|
39 |
+
prompt = gr.inputs.Textbox(lines=5, label="Введите промпт")
|
40 |
+
output = gr.outputs.Textbox(label="Сгенерированный текст")
|
41 |
+
iface = gr.Interface(fn=generate_text, inputs=prompt, outputs=output, title="Hugging Face Text Generator", theme="huggingface")
|
42 |
+
iface.launch()
|