Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,55 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import zipfile
|
| 3 |
-
import os
|
| 4 |
-
import pandas as pd
|
| 5 |
-
from sentence_transformers import SentenceTransformer
|
| 6 |
-
|
| 7 |
-
model = SentenceTransformer("csAhmad/zoraiz-model")
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
extract_path =
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
outputs=gr.File(label="Download Excel"),
|
| 57 |
-
title="ZIP to Excel Processor",
|
| 58 |
-
description="Upload ZIP → Extract files → Generate embeddings → Export Excel"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
demo.launch(share=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import zipfile
|
| 3 |
+
import os
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
|
| 7 |
+
model = SentenceTransformer("csAhmad/zoraiz-model")
|
| 8 |
+
|
| 9 |
+
os.makedirs("temp/extracted", exist_ok=True)
|
| 10 |
+
|
| 11 |
+
def process_zip(zip_file):
|
| 12 |
+
extract_path = "temp/extracted"
|
| 13 |
+
os.makedirs(extract_path, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
zip_path = zip_file.name # always works in Spaces
|
| 16 |
+
|
| 17 |
+
# Extract ZIP
|
| 18 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
| 19 |
+
zip_ref.extractall(extract_path)
|
| 20 |
+
|
| 21 |
+
results = []
|
| 22 |
+
|
| 23 |
+
# Example: process txt files
|
| 24 |
+
for file in os.listdir(extract_path):
|
| 25 |
+
if file.endswith(".txt"):
|
| 26 |
+
file_path = os.path.join(extract_path, file)
|
| 27 |
+
|
| 28 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 29 |
+
text = f.read()
|
| 30 |
+
|
| 31 |
+
emb = model.encode(text)
|
| 32 |
+
|
| 33 |
+
results.append({
|
| 34 |
+
"file": file,
|
| 35 |
+
"embedding_dim": len(emb),
|
| 36 |
+
"first_10_values": str(emb[:10])
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
df = pd.DataFrame(results)
|
| 40 |
+
|
| 41 |
+
output_file = "output.xlsx"
|
| 42 |
+
df.to_excel(output_file, index=False)
|
| 43 |
+
|
| 44 |
+
return output_file
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
+
fn=process_zip,
|
| 49 |
+
inputs=gr.File(file_types=[".zip"]),
|
| 50 |
+
outputs=gr.File(label="Download Excel"),
|
| 51 |
+
title="ZIP to Excel Processor",
|
| 52 |
+
description="Upload ZIP → Extract files → Generate embeddings → Export Excel"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|