13ze commited on
Commit
bd92b0c
·
verified ·
1 Parent(s): 50fd3de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -54
app.py CHANGED
@@ -1,58 +1,16 @@
1
- from flask import Flask, request, send_from_directory
2
- from PIL import Image
3
- import os
4
- import tempfile
5
 
6
- app = Flask(__name__)
7
 
8
- def convert_images(image_paths, height, width):
9
- converted_files = []
10
- for image_path in image_paths:
11
- img = Image.open(image_path).convert("RGBA")
12
- orig_width, orig_height = img.size
13
 
14
- if orig_height > height or orig_width > width:
15
- if orig_height / height > orig_width / width:
16
- new_height = height
17
- new_width = int((new_height / orig_height) * orig_width)
18
- else:
19
- new_width = width
20
- new_height = int((new_width / orig_width) * orig_height)
21
- else:
22
- new_width, new_height = orig_width, orig_height
23
 
24
- img = img.resize((new_width, new_height), Image.LANCZOS)
25
-
26
- base_name = os.path.splitext(os.path.basename(image_path))[0]
27
- temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".webp", prefix=base_name + "_")
28
- img.save(temp_file, format='WEBP')
29
- temp_file.close()
30
-
31
- converted_files.append(temp_file.name)
32
-
33
- return converted_files
34
-
35
- @app.route('/convert', methods=['POST'])
36
- def convert():
37
- files = request.files.getlist('images')
38
- height = int(request.form.get('height', 100))
39
- width = int(request.form.get('width', 200))
40
-
41
- image_paths = []
42
- for file in files:
43
- temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.filename)[1])
44
- file.save(temp_file.name)
45
- image_paths.append(temp_file.name)
46
-
47
- converted_files = convert_images(image_paths, height, width)
48
-
49
- return {
50
- "converted_files": [os.path.basename(f) for f in converted_files]
51
- }
52
-
53
- @app.route('/download/<filename>', methods=['GET'])
54
- def download(filename):
55
- return send_from_directory(tempfile.gettempdir(), filename)
56
-
57
- if __name__ == '__main__':
58
- app.run(host='0.0.0.0', port=5000)
 
1
+ import requests
 
 
 
2
 
3
+ url = 'https://api.jina.ai/v1/embeddings'
4
 
5
+ headers = {
6
+ 'Content-Type': 'application/json',
7
+ 'Authorization': 'Bearer jina_4736efa15c0c4e6781a9407683e9e320g-IB4U8jC54rCaxEF5XfmaPfdLXF'
8
+ }
 
9
 
10
+ data = {
11
+ 'input': ["Your text string goes here", "You can send multiple texts"],
12
+ 'model': 'jina-embeddings-v2-base-en',
13
+ 'encoding_type': 'float'
14
+ }
 
 
 
 
15
 
16
+ response = requests.post(url, headers=headers, json=data)