Lisandro commited on
Commit
e49bc91
·
1 Parent(s): 8565d7a

adfasdfad

Browse files
Files changed (2) hide show
  1. app.py +17 -9
  2. test_logic.py +46 -0
app.py CHANGED
@@ -757,19 +757,27 @@ def get_selection(evt: gr.SelectData, *args):
757
  version_title = ""
758
 
759
  if versions:
760
- # Has versions. Find default (match main weights or last one)
761
- main_weights = lora.get("weights")
 
 
 
762
 
763
- # Try to match by weights first
764
- found = False
765
- for i, v in enumerate(versions):
766
- if v.get("weights") == main_weights:
767
  version_index = i
768
- found = True
 
 
 
 
769
  break
770
 
771
- if not found:
772
- # Default to the last one if not found (convention mostly)
 
 
 
773
  version_index = len(versions) - 1
774
 
775
  version_data = versions[version_index]
 
757
  version_title = ""
758
 
759
  if versions:
760
+ # Has versions. Find best version or default to last.
761
+ found_best = False
762
+ found_default = False
763
+ default_version_index = -1
764
+ version_index = -1
765
 
766
+ for i, v in enumerate(versions, start=0):
767
+ if v.get("best", False):
 
 
768
  version_index = i
769
+ found_best = True
770
+ break
771
+ if v.get("weights") == lora.get("weights"):
772
+ default_version_index = i
773
+ found_default = True
774
  break
775
 
776
+ if not found_best:
777
+ if found_default:
778
+ version_index = default_version_index
779
+ else:
780
+ # Default to the last one if not found
781
  version_index = len(versions) - 1
782
 
783
  version_data = versions[version_index]
test_logic.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ def test_selection_logic():
3
+ # Helper to test logic
4
+ def get_selected_version_index(versions):
5
+ found_best = False
6
+ version_index = -1
7
+
8
+ for i, v in enumerate(versions, start=0):
9
+ if v.get("best", False):
10
+ version_index = i
11
+ found_best = True
12
+ break
13
+
14
+ if not found_best:
15
+ # Default to the last one if not found
16
+ version_index = len(versions) - 1
17
+
18
+ return version_index
19
+
20
+ # Case 1: No versions
21
+ # Case 2: Versions, none best -> Last one
22
+ versions_none_best = [
23
+ {"title": "v1"},
24
+ {"title": "v2"}
25
+ ]
26
+ assert get_selected_version_index(versions_none_best) == 1, "Should select last one (index 1)"
27
+
28
+ # Case 3: Versions, first is best -> First one
29
+ versions_first_best = [
30
+ {"title": "v1", "best": True},
31
+ {"title": "v2"}
32
+ ]
33
+ assert get_selected_version_index(versions_first_best) == 0, "Should select best one (index 0)"
34
+
35
+ # Case 4: Versions, second is best -> Second one
36
+ versions_second_best = [
37
+ {"title": "v1"},
38
+ {"title": "v2", "best": True},
39
+ {"title": "v3"}
40
+ ]
41
+ assert get_selected_version_index(versions_second_best) == 1, "Should select best one (index 1)"
42
+
43
+ print("All tests passed!")
44
+
45
+ if __name__ == "__main__":
46
+ test_selection_logic()