rahideer commited on
Commit
a3f5843
·
verified ·
1 Parent(s): 03c8514

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -47
app.py CHANGED
@@ -154,58 +154,51 @@ with col2:
154
  value=selected_pair["code2"] if selected_pair else "",
155
  help="Enter the second Java code snippet"
156
  )
157
-
158
- # Threshold slider
159
  threshold = st.slider(
160
  "Clone Detection Threshold",
161
- min_value=0.5,
162
- max_value=1.0,
163
- value=0.85,
164
  step=0.01,
165
- help="Adjust the similarity threshold for clone detection"
166
  )
167
 
168
- # Compare button
169
- if st.button("Compare Code", type="primary"):
170
- if tokenizer is None or code_model is None:
171
- st.error("Models failed to load. Please check the logs.")
172
- else:
173
- similarity = compare_code(code1, code2)
174
-
175
- if similarity is not None:
176
- # Display results
177
- st.subheader("Results")
178
-
179
- # Progress bar for visualization
180
- st.progress(similarity)
181
-
182
- # Metrics columns
183
- col1, col2, col3 = st.columns(3)
184
-
185
- with col1:
186
- st.metric("Similarity Score", f"{similarity:.3f}")
187
-
188
- with col2:
189
- st.metric("Threshold", f"{threshold:.3f}")
190
-
191
- with col3:
192
- is_clone = similarity >= threshold
193
- st.metric(
194
- "Clone Detection",
195
- "✅ Clone" if is_clone else "❌ Not a Clone",
196
- delta=f"{similarity-threshold:+.3f}"
197
- )
198
-
199
- # Show normalized code for debugging
200
- with st.expander("Show normalized code"):
201
- tab1, tab2 = st.tabs(["First Code", "Second Code"])
202
-
203
- with tab1:
204
- st.code(normalize_code(code1))
205
-
206
- with tab2:
207
- st.code(normalize_code(code2))
208
-
209
  # Footer
210
  st.markdown("---")
211
  st.markdown("""
 
154
  value=selected_pair["code2"] if selected_pair else "",
155
  help="Enter the second Java code snippet"
156
  )
157
+ # Threshold slider with proper value handling
 
158
  threshold = st.slider(
159
  "Clone Detection Threshold",
160
+ min_value=0.50,
161
+ max_value=1.00,
162
+ value=0.75, # Default middle value
163
  step=0.01,
164
+ help="Similarity score needed to consider code as cloned (0.5-1.0)"
165
  )
166
 
167
+ # In your comparison logic:
168
+ if similarity is not None:
169
+ # Display results with threshold comparison
170
+ is_clone = similarity >= threshold
171
+
172
+ st.subheader("Results")
173
+ col1, col2, col3 = st.columns(3)
174
+
175
+ with col1:
176
+ st.metric("Similarity Score", f"{similarity:.3f}")
177
+
178
+ with col2:
179
+ # Show the current threshold being used
180
+ st.metric("Current Threshold", f"{threshold:.3f}")
181
+
182
+ with col3:
183
+ # Visual clone decision
184
+ st.metric(
185
+ "Verdict",
186
+ "✅ CLONE" if is_clone else "❌ NOT CLONE",
187
+ delta=f"{similarity-threshold:+.3f}",
188
+ help=f"Score {'≥' if is_clone else '<'} threshold"
189
+ )
190
+
191
+ # Visual indicator
192
+ st.progress(similarity)
193
+
194
+ # Interpretation guide
195
+ with st.expander("Interpretation Guide"):
196
+ st.markdown("""
197
+ - **> 0.95**: Nearly identical (Type-1 clone)
198
+ - **0.85-0.95**: Very similar (Type-2 clone)
199
+ - **0.70-0.85**: Similar structure (Type-3 clone)
200
+ - **< 0.70**: Different code
201
+ """)
 
 
 
 
 
 
202
  # Footer
203
  st.markdown("---")
204
  st.markdown("""