HawkClaws commited on
Commit
52e0217
1 Parent(s): cb489b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -20
app.py CHANGED
@@ -99,23 +99,43 @@ st.title("Model Structure Comparison Tool")
99
  model_id1 = st.text_input("Enter the first HuggingFace Model ID")
100
  model_id2 = st.text_input("Enter the second HuggingFace Model ID")
101
 
102
- if model_id1 and model_id2:
103
- struct1 = get_model_structure(model_id1)
104
- struct2 = get_model_structure(model_id2)
105
-
106
- diff = compare_structures(struct1, struct2)
107
- left_html, right_html, diff_found = display_diff(diff)
108
-
109
- st.write("### Comparison Result")
110
- if not diff_found:
111
- st.success("The model structures are identical.")
112
-
113
- col1, col2 = st.columns([1.5, 1.5]) # Adjust the ratio to make columns wider
114
-
115
- with col1:
116
- st.write("### Model 1")
117
- st.markdown(left_html, unsafe_allow_html=True)
118
-
119
- with col2:
120
- st.write("### Model 2")
121
- st.markdown(right_html, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  model_id1 = st.text_input("Enter the first HuggingFace Model ID")
100
  model_id2 = st.text_input("Enter the second HuggingFace Model ID")
101
 
102
+ if "compare_button_clicked" not in st.session_state:
103
+ st.session_state.compare_button_clicked = False
104
+
105
+ if st.session_state.compare_button_clicked:
106
+ with st.spinner('Comparing models and loading tokenizers...'):
107
+ if model_id1 and model_id2:
108
+ struct1 = get_model_structure(model_id1)
109
+ struct2 = get_model_structure(model_id2)
110
+
111
+ diff = compare_structures(struct1, struct2)
112
+ left_html, right_html, diff_found = display_diff(diff)
113
+
114
+ st.write("### Comparison Result")
115
+ if not diff_found:
116
+ st.success("The model structures are identical.")
117
+
118
+ col1, col2 = st.columns([1.5, 1.5]) # Adjust the ratio to make columns wider
119
+
120
+ with col1:
121
+ st.write("### Model 1")
122
+ st.markdown(left_html, unsafe_allow_html=True)
123
+
124
+ with col2:
125
+ st.write("### Model 2")
126
+ st.markdown(right_html, unsafe_allow_html=True)
127
+
128
+ # Tokenizer verification
129
+ try:
130
+ tokenizer1 = AutoTokenizer.from_pretrained(model_id1)
131
+ tokenizer2 = AutoTokenizer.from_pretrained(model_id2)
132
+ st.write(f"**{model_id1} Tokenizer Vocab Size**: {tokenizer1.vocab_size}")
133
+ st.write(f"**{model_id2} Tokenizer Vocab Size**: {tokenizer2.vocab_size}")
134
+ except Exception as e:
135
+ st.error(f"Error loading tokenizers: {e}")
136
+ else:
137
+ st.error("Please enter both model IDs.")
138
+ st.session_state.compare_button_clicked = False
139
+ else:
140
+ if st.button("Compare Models"):
141
+ st.session_state.compare_button_clicked = True