Spaces:
Running
Running
[modify] update main.py
Browse files- README.md +1 -1
- app/__init__.py +0 -0
- app.py → app/main.py +20 -29
- app/utils.py +15 -0
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: green
|
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.3.0
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: This project is a GUI for the gpustack/gguf-parser-go
|
|
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 5.3.0
|
8 |
+
app_file: app/main.py
|
9 |
pinned: false
|
10 |
license: mit
|
11 |
short_description: This project is a GUI for the gpustack/gguf-parser-go
|
app/__init__.py
ADDED
File without changes
|
app.py → app/main.py
RENAMED
@@ -8,15 +8,22 @@ import pandas as pd
|
|
8 |
GGUF_PARSER_VERSION = os.getenv("GGUF_PARSER_VERSION", "v0.12.0")
|
9 |
gguf_parser = Path("gguf-parser-linux-amd64")
|
10 |
gguf_parser_url = f"https://github.com/gpustack/gguf-parser-go/releases/download/{GGUF_PARSER_VERSION}/{gguf_parser}"
|
|
|
11 |
|
12 |
|
13 |
-
def process_url(url):
|
14 |
try:
|
15 |
-
res = os.popen(
|
|
|
|
|
16 |
data = json.loads(res)
|
17 |
|
|
|
|
|
18 |
architecture_df = pd.DataFrame([data["architecture"]])
|
19 |
|
|
|
|
|
20 |
estimate_df = pd.DataFrame(
|
21 |
[
|
22 |
{
|
@@ -32,47 +39,31 @@ def process_url(url):
|
|
32 |
]
|
33 |
)
|
34 |
|
35 |
-
metadata_df
|
36 |
-
|
37 |
-
tokenizer_df = pd.DataFrame([data["tokenizer"]])
|
38 |
-
|
39 |
-
return architecture_df, estimate_df, metadata_df, tokenizer_df
|
40 |
except Exception as e:
|
41 |
return e
|
42 |
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
if not gguf_parser.exists():
|
46 |
-
os.system(f"wget {gguf_parser_url}")
|
47 |
-
os.system(f"chmod +x {gguf_parser}")
|
48 |
|
49 |
with open("devices.json", "r", encoding="utf-8") as f:
|
50 |
device_list = json.load(f)
|
51 |
|
52 |
-
with gr.Blocks(title="GGUF
|
53 |
-
url_input = gr.Textbox(
|
54 |
-
|
55 |
-
|
56 |
-
gr.Markdown("### 模型架構")
|
57 |
-
architecture_table = gr.DataFrame()
|
58 |
-
|
59 |
-
gr.Markdown("### 效能評估")
|
60 |
-
estimate_table = gr.DataFrame()
|
61 |
-
|
62 |
-
gr.Markdown("### 中繼資料")
|
63 |
-
metadata_table = gr.DataFrame()
|
64 |
-
|
65 |
-
gr.Markdown("### 分詞器")
|
66 |
-
tokenizer_table = gr.DataFrame()
|
67 |
|
68 |
submit_btn.click(
|
69 |
fn=process_url,
|
70 |
-
inputs=url_input,
|
71 |
outputs=[
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
],
|
77 |
)
|
78 |
iface.launch()
|
|
|
8 |
GGUF_PARSER_VERSION = os.getenv("GGUF_PARSER_VERSION", "v0.12.0")
|
9 |
gguf_parser = Path("gguf-parser-linux-amd64")
|
10 |
gguf_parser_url = f"https://github.com/gpustack/gguf-parser-go/releases/download/{GGUF_PARSER_VERSION}/{gguf_parser}"
|
11 |
+
DEFAULT_URL = "https://huggingface.co/phate334/Llama-3.1-8B-Instruct-Q4_K_M-GGUF/resolve/main/llama-3.1-8b-instruct-q4_k_m.gguf"
|
12 |
|
13 |
|
14 |
+
def process_url(url, context_length):
|
15 |
try:
|
16 |
+
res = os.popen(
|
17 |
+
f"./{gguf_parser} --ctx-size={context_length} -url {url} --json"
|
18 |
+
).read()
|
19 |
data = json.loads(res)
|
20 |
|
21 |
+
metadata_df = pd.DataFrame([data["metadata"]])
|
22 |
+
|
23 |
architecture_df = pd.DataFrame([data["architecture"]])
|
24 |
|
25 |
+
tokenizer_df = pd.DataFrame([data["tokenizer"]])
|
26 |
+
|
27 |
estimate_df = pd.DataFrame(
|
28 |
[
|
29 |
{
|
|
|
39 |
]
|
40 |
)
|
41 |
|
42 |
+
return metadata_df, architecture_df, tokenizer_df, estimate_df
|
|
|
|
|
|
|
|
|
43 |
except Exception as e:
|
44 |
return e
|
45 |
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
if not gguf_parser.exists():
|
49 |
+
os.system(f"wget {gguf_parser_url}&&chmod +x {gguf_parser}")
|
|
|
50 |
|
51 |
with open("devices.json", "r", encoding="utf-8") as f:
|
52 |
device_list = json.load(f)
|
53 |
|
54 |
+
with gr.Blocks(title="GGUF Parser") as iface:
|
55 |
+
url_input = gr.Textbox(placeholder="Enter GGUF URL", value=DEFAULT_URL)
|
56 |
+
context_length = gr.Number(label="Context Length", value=8192)
|
57 |
+
submit_btn = gr.Button("Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
submit_btn.click(
|
60 |
fn=process_url,
|
61 |
+
inputs=[url_input, context_length],
|
62 |
outputs=[
|
63 |
+
gr.DataFrame(label="METADATA"),
|
64 |
+
gr.DataFrame(label="ARCHITECTURE"),
|
65 |
+
gr.DataFrame(label="TOKENIZER"),
|
66 |
+
gr.DataFrame(label="ESTIMATE"),
|
67 |
],
|
68 |
)
|
69 |
iface.launch()
|
app/utils.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def human_readable_size(size_in_bytes: int) -> str:
|
2 |
+
# 將檔案大小轉換為人類可讀的格式
|
3 |
+
for unit in ["B", "KB", "MB", "GB", "TB", "PB"]:
|
4 |
+
if size_in_bytes < 1024:
|
5 |
+
return f"{size_in_bytes:.2f}{unit}"
|
6 |
+
size_in_bytes /= 1024
|
7 |
+
return f"{size_in_bytes:.2f}EB"
|
8 |
+
|
9 |
+
|
10 |
+
def abbreviate_number(number: int) -> str:
|
11 |
+
# 將大數字轉換為縮寫格式
|
12 |
+
for unit, threshold in [("B", 1e9), ("M", 1e6), ("K", 1e3)]:
|
13 |
+
if number >= threshold:
|
14 |
+
return f"{number/threshold:.2f}{unit}"
|
15 |
+
return str(number)
|