Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,69 +1,76 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import os
|
|
|
6 |
|
7 |
-
title_and_description = """
|
8 |
-
# PDF to Word & Word to PDF
|
9 |
-
"""
|
10 |
|
11 |
-
def
|
12 |
-
docx_filename = pdf_file.name.replace('.pdf', '.docx')
|
13 |
-
|
14 |
-
cv = Converter(pdf_file.name)
|
15 |
-
cv.convert(docx_filename, multi_processing=True, start=0, end=None)
|
16 |
-
cv.close()
|
17 |
-
|
18 |
-
return docx_filename
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
doc = Document(docx_file.name)
|
24 |
-
pdf = FPDF(format='A4')
|
25 |
-
pdf.set_auto_page_break(auto=True, margin=15)
|
26 |
-
pdf.add_page()
|
27 |
-
pdf.add_font('Arial', '', 'Arial.ttf', uni=True)
|
28 |
-
pdf.set_font('Arial', size=12)
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
for word in words:
|
38 |
-
if pdf.get_string_width(line + word) < (pdf.w - 2 * pdf.l_margin):
|
39 |
-
line += word + ' '
|
40 |
-
else:
|
41 |
-
pdf.cell(0, 10, line, ln=True)
|
42 |
-
line = word + ' '
|
43 |
-
if line:
|
44 |
-
pdf.cell(0, 10, line, ln=True)
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
pdf_input = gr.File(label="Upload PDF")
|
56 |
-
convert_pdf_to_word = gr.Button("Convert to Word")
|
57 |
-
word_output = gr.File(label="Download Word file", type="filepath")
|
58 |
-
|
59 |
-
convert_pdf_to_word.click(pdf_to_word, inputs=[pdf_input], outputs=[word_output])
|
60 |
-
|
61 |
-
with gr.Column():
|
62 |
-
with gr.Accordion("Word to PDF"):
|
63 |
-
word_input = gr.File(label="Upload Word")
|
64 |
-
convert_word_to_pdf = gr.Button("Convert to PDF")
|
65 |
-
pdf_output = gr.File(label="Download PDF file", type="filepath")
|
66 |
-
|
67 |
-
convert_word_to_pdf.click(word_to_pdf, inputs=[word_input], outputs=[pdf_output])
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -* coding:UTF-8 -*
|
2 |
+
# !/usr/bin/env python
|
3 |
+
import numpy as np
|
4 |
import gradio as gr
|
5 |
+
import roop.globals
|
6 |
+
from roop.core import (
|
7 |
+
start,
|
8 |
+
decode_execution_providers,
|
9 |
+
suggest_max_memory,
|
10 |
+
suggest_execution_threads,
|
11 |
+
)
|
12 |
+
from roop.processors.frame.core import get_frame_processors_modules
|
13 |
+
from roop.utilities import normalize_output_path
|
14 |
import os
|
15 |
+
from PIL import Image
|
16 |
|
|
|
|
|
|
|
17 |
|
18 |
+
def swap_face(source_file, target_file, doFaceEnhancer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
source_path = "input.jpg"
|
21 |
+
target_path = "target.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
source_image = Image.fromarray(source_file)
|
24 |
+
source_image.save(source_path)
|
25 |
+
target_image = Image.fromarray(target_file)
|
26 |
+
target_image.save(target_path)
|
27 |
|
28 |
+
print("source_path: ", source_path)
|
29 |
+
print("target_path: ", target_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
roop.globals.source_path = source_path
|
32 |
+
roop.globals.target_path = target_path
|
33 |
+
output_path = "output.jpg"
|
34 |
+
roop.globals.output_path = normalize_output_path(
|
35 |
+
roop.globals.source_path, roop.globals.target_path, output_path
|
36 |
+
)
|
37 |
+
if doFaceEnhancer == True:
|
38 |
+
roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
|
39 |
+
else:
|
40 |
+
roop.globals.frame_processors = ["face_swapper"]
|
41 |
+
roop.globals.headless = True
|
42 |
+
roop.globals.keep_fps = True
|
43 |
+
roop.globals.keep_audio = True
|
44 |
+
roop.globals.keep_frames = False
|
45 |
+
roop.globals.many_faces = False
|
46 |
+
roop.globals.video_encoder = "libx264"
|
47 |
+
roop.globals.video_quality = 18
|
48 |
+
roop.globals.max_memory = suggest_max_memory()
|
49 |
+
roop.globals.execution_providers = decode_execution_providers(["cuda"])
|
50 |
+
roop.globals.execution_threads = suggest_execution_threads()
|
51 |
|
52 |
+
print(
|
53 |
+
"start process",
|
54 |
+
roop.globals.source_path,
|
55 |
+
roop.globals.target_path,
|
56 |
+
roop.globals.output_path,
|
57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
for frame_processor in get_frame_processors_modules(
|
60 |
+
roop.globals.frame_processors
|
61 |
+
):
|
62 |
+
if not frame_processor.pre_check():
|
63 |
+
return
|
64 |
+
|
65 |
+
start()
|
66 |
+
return output_path
|
67 |
+
|
68 |
+
|
69 |
+
app = gr.Interface(
|
70 |
+
fn=swap_face,
|
71 |
+
inputs=[gr.Image(), gr.Image(), gr.Checkbox(label="face_enhancer?", info="do face enhancer?")],
|
72 |
+
outputs="image"
|
73 |
+
)
|
74 |
+
|
75 |
+
# Launch the Gradio interface with the specified theme
|
76 |
+
app.launch(theme="xiaobaiyuan/theme_brief")
|