AndreySokolov01 commited on
Commit
8d15bc3
·
verified ·
1 Parent(s): ef60743

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -4
app.py CHANGED
@@ -1,7 +1,46 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ # ...
 
4
 
5
+ with gr.Blocks() as demo:
6
+ with gr.Row():
7
+ chatbot = gr.Chatbot()
8
+ with gr.Column():
9
+ user_input = gr.Textbox(label="Введите текст из чата")
10
+ generate_button = gr.Button("Сохранить в PDF")
11
+ pdf_link = gr.Textbox(label="Ссылка на PDF")
12
+
13
+ generate_button.click(generate_pdf, inputs=[user_input], outputs=[pdf_link])
14
+
15
+ import pdfkit
16
+
17
+ def generate_pdf(text):
18
+ # Создаем HTML-файл с текстом
19
+ html_content = f"""
20
+ <!DOCTYPE html>
21
+ <html>
22
+ <head>
23
+ <title>Диалог из чата</title>
24
+ <style>
25
+ body {{
26
+ font-family: Arial, sans-serif;
27
+ font-size: 14px;
28
+ line-height: 1.5;
29
+ }}
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <h1>Диалог из чата</h1>
34
+ <p>{text}</p>
35
+ </body>
36
+ </html>
37
+ """
38
+
39
+ # Сохраняем HTML-файл
40
+ with open("chat_dialog.html", "w", encoding="utf-8") as html_file:
41
+ html_file.write(html_content)
42
+
43
+ # Конвертируем HTML в PDF
44
+ pdfkit.from_file("chat_dialog.html", "chat_dialog.pdf")
45
+
46
+ return "chat_dialog.pdf"