TheFrenchDemos commited on
Commit
5b80bd0
·
1 Parent(s): ee68dca

Update app.py

Browse files

suppression de init_model

Files changed (1) hide show
  1. app.py +40 -40
app.py CHANGED
@@ -32,40 +32,40 @@ def get_photo_id(url):
32
  except:
33
  return None
34
 
35
- def get_other_info(url):
36
- """Get author information from Flickr"""
37
- try:
38
- photo_id = get_photo_id(url)
39
- if photo_id:
40
- photo_info = flickr.photos.getInfo(photo_id=photo_id)
41
- license = photo_info['photo']['license']
42
- owner = photo_info['photo']['owner']
43
- flickr_url = f"https://www.flickr.com/photos/{owner.get('nsid', '')}/{photo_id}"
44
- return {
45
- 'username': owner.get('username', ''),
46
- 'realname': owner.get('realname', ''),
47
- 'nsid': owner.get('nsid', ''),
48
- 'flickr_url': flickr_url,
49
- 'license': license
50
- }
51
- except:
52
- pass
53
- return {
54
- 'username': 'Unknown',
55
- 'realname': 'Unknown',
56
- 'nsid': '',
57
- 'flickr_url': '',
58
- 'license': 'Unknown'
59
- }
60
-
61
-
62
- def load_model():
63
- """Load DINOv2 model once and cache it"""
64
- torch.hub.set_dir('static')
65
- model = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
66
- model.eval()
67
- model.to(torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
68
- return model
69
 
70
  def load_index(index_path):
71
  """Load FAISS index once and cache it"""
@@ -188,12 +188,12 @@ def select_preset(preset_id):
188
 
189
  # Build final results
190
  results = []
191
- for i, result in enumerate(valid_results):
192
- other_info = get_other_info(result['url'])
193
- results.append({
194
- 'image_url': result['url'],
195
- 'rewards': rewards[i],
196
- 'other': other_info
197
  })
198
 
199
  return jsonify({'results': results})
 
32
  except:
33
  return None
34
 
35
+ ### def get_other_info(url):
36
+ ### """Get author information from Flickr"""
37
+ ### try:
38
+ ### photo_id = get_photo_id(url)
39
+ ### if photo_id:
40
+ ### photo_info = flickr.photos.getInfo(photo_id=photo_id)
41
+ ### license = photo_info['photo']['license']
42
+ ### owner = photo_info['photo']['owner']
43
+ ### flickr_url = f"https://www.flickr.com/photos/{owner.get('nsid', '')}/{photo_id}"
44
+ ### return {
45
+ ### 'username': owner.get('username', ''),
46
+ ### 'realname': owner.get('realname', ''),
47
+ ### 'nsid': owner.get('nsid', ''),
48
+ ### 'flickr_url': flickr_url,
49
+ ### 'license': license
50
+ ### }
51
+ ### except:
52
+ ### pass
53
+ ### return {
54
+ ### 'username': 'Unknown',
55
+ ### 'realname': 'Unknown',
56
+ ### 'nsid': '',
57
+ ### 'flickr_url': '',
58
+ ### 'license': 'Unknown'
59
+ ### }
60
+
61
+
62
+ ### def load_model():
63
+ ### """Load DINOv2 model once and cache it"""
64
+ ### torch.hub.set_dir('static')
65
+ ### model = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14')
66
+ ### model.eval()
67
+ ### model.to(torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
68
+ ### return model
69
 
70
  def load_index(index_path):
71
  """Load FAISS index once and cache it"""
 
188
 
189
  # Build final results
190
  results = []
191
+ ### for i, result in enumerate(valid_results):
192
+ ### other_info = get_other_info(result['url'])
193
+ ### results.append({
194
+ ### 'image_url': result['url'],
195
+ ### 'rewards': rewards[i],
196
+ ### 'other': other_info
197
  })
198
 
199
  return jsonify({'results': results})