Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
|
5 |
+
def convert_index(file):
|
6 |
+
with open(file.name, 'r') as f:
|
7 |
+
data = json.load(f)
|
8 |
+
|
9 |
+
new_data = {k: v for k, v in data.items()}
|
10 |
+
new_data['weight_map'] = {k: v.replace('pytorch_model', 'model').replace('.bin', '.safetensors') for k, v in data['weight_map'].items()}
|
11 |
+
|
12 |
+
output_path = os.path.join(os.path.dirname(file.name), 'model.safetensors.index.json')
|
13 |
+
with open(output_path, 'w') as f:
|
14 |
+
json.dump(new_data, f, indent=4)
|
15 |
+
|
16 |
+
return output_path
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=convert_index,
|
20 |
+
inputs=gr.File(label="Upload pytorch_model.bin.index.json"),
|
21 |
+
outputs=gr.File(label="Download model.safetensors.index.json"),
|
22 |
+
title="Convert PyTorch Index to SafeTensors Index",
|
23 |
+
description="Upload a pytorch_model.bin.index.json file to convert it to model.safetensors.index.json"
|
24 |
+
)
|
25 |
+
|
26 |
+
iface.launch()
|