Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
-
from transformers import AutoModelForCausalLM
|
4 |
import difflib
|
5 |
import requests
|
6 |
import os
|
@@ -31,7 +31,6 @@ def get_model_structure(model_id):
|
|
31 |
save_to_firebase(model_id, structure)
|
32 |
return structure
|
33 |
|
34 |
-
|
35 |
def compare_structures(struct1, struct2):
|
36 |
struct1_lines = [f"{k}: {v}" for k, v in struct1.items()]
|
37 |
struct2_lines = [f"{k}: {v}" for k, v in struct2.items()]
|
@@ -87,23 +86,36 @@ st.title("Model Structure Comparison Tool")
|
|
87 |
model_id1 = st.text_input("Enter the first HuggingFace Model ID")
|
88 |
model_id2 = st.text_input("Enter the second HuggingFace Model ID")
|
89 |
|
90 |
-
if
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
import difflib
|
5 |
import requests
|
6 |
import os
|
|
|
31 |
save_to_firebase(model_id, structure)
|
32 |
return structure
|
33 |
|
|
|
34 |
def compare_structures(struct1, struct2):
|
35 |
struct1_lines = [f"{k}: {v}" for k, v in struct1.items()]
|
36 |
struct2_lines = [f"{k}: {v}" for k, v in struct2.items()]
|
|
|
86 |
model_id1 = st.text_input("Enter the first HuggingFace Model ID")
|
87 |
model_id2 = st.text_input("Enter the second HuggingFace Model ID")
|
88 |
|
89 |
+
if st.button("Compare Models"):
|
90 |
+
if model_id1 and model_id2:
|
91 |
+
struct1 = get_model_structure(model_id1)
|
92 |
+
struct2 = get_model_structure(model_id2)
|
93 |
+
|
94 |
+
diff = compare_structures(struct1, struct2)
|
95 |
+
left_html, right_html, diff_found = display_diff(diff)
|
96 |
+
|
97 |
+
st.write("### Comparison Result")
|
98 |
+
if not diff_found:
|
99 |
+
st.success("The model structures are identical.")
|
100 |
+
|
101 |
+
col1, col2 = st.columns([1.5, 1.5]) # Adjust the ratio to make columns wider
|
102 |
|
103 |
+
with col1:
|
104 |
+
st.write("### Model 1")
|
105 |
+
st.markdown(left_html, unsafe_allow_html=True)
|
106 |
|
107 |
+
with col2:
|
108 |
+
st.write("### Model 2")
|
109 |
+
st.markdown(right_html, unsafe_allow_html=True)
|
110 |
+
|
111 |
+
# Tokenizer verification
|
112 |
+
with st.spinner('Loading tokenizers...'):
|
113 |
+
try:
|
114 |
+
tokenizer1 = AutoTokenizer.from_pretrained(model_id1)
|
115 |
+
tokenizer2 = AutoTokenizer.from_pretrained(model_id2)
|
116 |
+
st.write(f"**{model_id1} Tokenizer Vocab Size**: {tokenizer1.vocab_size}")
|
117 |
+
st.write(f"**{model_id2} Tokenizer Vocab Size**: {tokenizer2.vocab_size}")
|
118 |
+
except Exception as e:
|
119 |
+
st.error(f"Error loading tokenizers: {e}")
|
120 |
+
else:
|
121 |
+
st.error("Please enter both model IDs.")
|