vishalkatheriya18 commited on
Commit
6027458
1 Parent(s): 1f9a45b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -5,6 +5,7 @@ import requests
5
  from io import BytesIO
6
  import threading
7
  import time
 
8
 
9
  # Load models and processor only once using session state
10
  if 'models_loaded' not in st.session_state:
@@ -51,12 +52,17 @@ def pipes(imagepath):
51
  encoding, image = imageprocessing(imagepath)
52
  # Using threading for faster results
53
  results = [None] * 4
 
 
 
 
54
  threads = [
55
- threading.Thread(target=lambda: results.__setitem__(0, topwear(encoding))),
56
- threading.Thread(target=lambda: results.__setitem__(1, patterns(encoding))),
57
- threading.Thread(target=lambda: results.__setitem__(2, prints(encoding))),
58
- threading.Thread(target=lambda: results.__setitem__(3, sleevelengths(encoding))),
59
  ]
 
60
  for thread in threads:
61
  thread.start()
62
  for thread in threads:
@@ -75,11 +81,8 @@ if image_url:
75
  results, img = pipes(image_url)
76
  st.image(img.resize((200, 200)), caption="Uploaded Image", use_column_width=False)
77
 
78
- # Display results
79
- st.write("Classification Results:")
80
- st.write(f"Topwear: {results['top']}")
81
- st.write(f"Pattern: {results['pattern']}")
82
- st.write(f"Print: {results['print']}")
83
- st.write(f"Sleeve Length: {results['sleeve_length']}")
84
 
85
  st.write(f"Time taken: {time.time() - start_time:.2f} seconds")
 
5
  from io import BytesIO
6
  import threading
7
  import time
8
+ import json
9
 
10
  # Load models and processor only once using session state
11
  if 'models_loaded' not in st.session_state:
 
52
  encoding, image = imageprocessing(imagepath)
53
  # Using threading for faster results
54
  results = [None] * 4
55
+
56
+ def update_results(index, func):
57
+ results[index] = func(encoding)
58
+
59
  threads = [
60
+ threading.Thread(target=update_results, args=(0, topwear)),
61
+ threading.Thread(target=update_results, args=(1, patterns)),
62
+ threading.Thread(target=update_results, args=(2, prints)),
63
+ threading.Thread(target=update_results, args=(3, sleevelengths)),
64
  ]
65
+
66
  for thread in threads:
67
  thread.start()
68
  for thread in threads:
 
81
  results, img = pipes(image_url)
82
  st.image(img.resize((200, 200)), caption="Uploaded Image", use_column_width=False)
83
 
84
+ # Display results as JSON
85
+ st.write("Classification Results (JSON):")
86
+ st.json(results) # Output as JSON
 
 
 
87
 
88
  st.write(f"Time taken: {time.time() - start_time:.2f} seconds")