Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
def
|
| 6 |
if file is None:
|
| 7 |
-
return ""
|
|
|
|
| 8 |
try:
|
| 9 |
-
with
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
except Exception as e:
|
| 13 |
-
return f"Ошибка
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
-
gr.Markdown("##
|
| 17 |
-
|
| 18 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
file_input.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import bz2
|
|
|
|
| 3 |
|
| 4 |
+
def analyze_cps(file):
|
| 5 |
if file is None:
|
| 6 |
+
return "", ""
|
| 7 |
+
|
| 8 |
try:
|
| 9 |
+
with open(file.name, "rb") as f:
|
| 10 |
+
raw_data = f.read()
|
| 11 |
+
|
| 12 |
+
# Показываем первые 256 байт в HEX
|
| 13 |
+
hex_dump = ' '.join(f'{byte:02x}' for byte in raw_data[:256])
|
| 14 |
+
hex_display = f"HEX дамп (первые 256 байт):\n{hex_dump}"
|
| 15 |
+
|
| 16 |
+
# Пробуем распаковать через bz2
|
| 17 |
+
try:
|
| 18 |
+
decompressed = bz2.decompress(raw_data)
|
| 19 |
+
text_output = decompressed.decode("utf-8", errors="replace")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
text_output = f"[Не удалось распаковать как bzip2]: {e}"
|
| 22 |
+
|
| 23 |
+
return hex_display, text_output
|
| 24 |
+
|
| 25 |
except Exception as e:
|
| 26 |
+
return f"Ошибка чтения файла: {e}", ""
|
| 27 |
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## Анализ .cps файла")
|
| 30 |
+
|
| 31 |
file_input = gr.File(label="Загрузите .cps файл", file_types=[".cps"])
|
| 32 |
+
hex_output = gr.Textbox(label="HEX дамп файла", lines=5)
|
| 33 |
+
text_output = gr.Textbox(label="Распакованный текст / ошибка", lines=10)
|
| 34 |
+
|
| 35 |
+
file_input.change(
|
| 36 |
+
fn=analyze_cps,
|
| 37 |
+
inputs=file_input,
|
| 38 |
+
outputs=[hex_output, text_output]
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
file_input.clear(
|
| 42 |
+
fn=lambda: ("", ""),
|
| 43 |
+
outputs=[hex_output, text_output]
|
| 44 |
+
)
|
| 45 |
|
| 46 |
demo.launch()
|