Create App2nd.py
Browse files
App2nd.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
def process_text(text):
|
| 5 |
+
# Создаем DataFrame с введенным текстом
|
| 6 |
+
data = {'text': [text]}
|
| 7 |
+
df = pd.DataFrame(data)
|
| 8 |
+
|
| 9 |
+
# Сохраняем в память (BytesIO объект)
|
| 10 |
+
buffer = BytesIO()
|
| 11 |
+
df.to_csv(buffer, index=False)
|
| 12 |
+
buffer.seek(0) # Сбрасываем указатель
|
| 13 |
+
|
| 14 |
+
return buffer
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
with gr.Blocks() as demo:
|
| 18 |
+
with gr.Row():
|
| 19 |
+
text_input = gr.Textbox(label="Введите текст")
|
| 20 |
+
|
| 21 |
+
with gr.Row():
|
| 22 |
+
send_button = gr.Button("Отправить")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
download_button = gr.DownloadButton(label="Скачать CSV")
|
| 26 |
+
|
| 27 |
+
# Функция, вызываемая при нажатии кнопки "Отправить"
|
| 28 |
+
def on_send(text):
|
| 29 |
+
return process_text(text)
|
| 30 |
+
|
| 31 |
+
send_button.click(on_send, inputs=text_input, outputs=download_button)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
main()
|