Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import hashlib
|
3 |
+
|
4 |
+
def calculate_sha256(file_path):
|
5 |
+
"""Вычисляет SHA256 хеш файла."""
|
6 |
+
hasher = hashlib.sha256()
|
7 |
+
with open(file_path, 'rb') as file:
|
8 |
+
while True:
|
9 |
+
chunk = file.read(4096)
|
10 |
+
if not chunk:
|
11 |
+
break
|
12 |
+
hasher.update(chunk)
|
13 |
+
return hasher.hexdigest()
|
14 |
+
|
15 |
+
def compare_files(file1, file2):
|
16 |
+
"""Сравнивает два файла на основе их SHA256 хеша."""
|
17 |
+
if file1 is None or file2 is None:
|
18 |
+
return "Выберите оба файла."
|
19 |
+
|
20 |
+
hash1 = calculate_sha256(file1.name)
|
21 |
+
hash2 = calculate_sha256(file2.name)
|
22 |
+
|
23 |
+
if hash1 == hash2:
|
24 |
+
return "Файлы одинаковые."
|
25 |
+
else:
|
26 |
+
return "Файлы разные."
|
27 |
+
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=compare_files,
|
30 |
+
inputs=[
|
31 |
+
gr.File(label="Файл 1"),
|
32 |
+
gr.File(label="Файл 2")
|
33 |
+
],
|
34 |
+
outputs="text",
|
35 |
+
title="Сравнение файлов по хешу SHA256",
|
36 |
+
description="Загрузите два файла для сравнения их хешей."
|
37 |
+
)
|
38 |
+
|
39 |
+
iface.launch()
|