Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
solve conflict
Browse files- app.py +19 -2
- requirements.txt +0 -1
app.py
CHANGED
@@ -6,7 +6,9 @@ import json
|
|
6 |
import requests
|
7 |
import time
|
8 |
from concurrent.futures import ThreadPoolExecutor
|
9 |
-
from
|
|
|
|
|
10 |
|
11 |
DESCRIPTION = '''<h2 style='text-align: center'> <a href="https://github.com/THUDM/CogVLM2"> CogVLM2 </a></h2>'''
|
12 |
|
@@ -14,11 +16,26 @@ NOTES = 'This app is adapted from <a href="https://github.com/THUDM/CogVLM">http
|
|
14 |
|
15 |
MAINTENANCE_NOTICE1 = 'Hint 1: If the app report "Something went wrong, connection error out", please turn off your proxy and retry.<br>Hint 2: If you upload a large size of image like 10MB, it may take some time to upload and process. Please be patient and wait.'
|
16 |
|
17 |
-
|
18 |
default_chatbox = [("", "Hi, What do you want to know about this image?")]
|
19 |
|
20 |
URL = os.environ.get("URL")
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def make_request(URL, headers, data):
|
24 |
response = requests.request("POST", URL, headers=headers, data=data, timeout=(60, 100))
|
|
|
6 |
import requests
|
7 |
import time
|
8 |
from concurrent.futures import ThreadPoolExecutor
|
9 |
+
from PIL import Image
|
10 |
+
import base64
|
11 |
+
import hashlib
|
12 |
|
13 |
DESCRIPTION = '''<h2 style='text-align: center'> <a href="https://github.com/THUDM/CogVLM2"> CogVLM2 </a></h2>'''
|
14 |
|
|
|
16 |
|
17 |
MAINTENANCE_NOTICE1 = 'Hint 1: If the app report "Something went wrong, connection error out", please turn off your proxy and retry.<br>Hint 2: If you upload a large size of image like 10MB, it may take some time to upload and process. Please be patient and wait.'
|
18 |
|
|
|
19 |
default_chatbox = [("", "Hi, What do you want to know about this image?")]
|
20 |
|
21 |
URL = os.environ.get("URL")
|
22 |
|
23 |
+
def process_image_without_resize(image_prompt):
|
24 |
+
image = Image.open(image_prompt)
|
25 |
+
print(f"height:{image.height}, width:{image.width}")
|
26 |
+
timestamp = time.time()
|
27 |
+
file_ext = os.path.splitext(image_prompt)[1]
|
28 |
+
filename = f"examples/{timestamp}{file_ext}"
|
29 |
+
filename_grounding = f"examples/{timestamp}_grounding{file_ext}"
|
30 |
+
image.save(filename)
|
31 |
+
print(f"temporal filename {filename}")
|
32 |
+
with open(filename, "rb") as image_file:
|
33 |
+
bytes = base64.b64encode(image_file.read())
|
34 |
+
encoded_img = str(bytes, encoding='utf-8')
|
35 |
+
image_hash = hashlib.sha256(bytes).hexdigest()
|
36 |
+
os.remove(filename)
|
37 |
+
return image, encoded_img, image_hash, filename_grounding
|
38 |
+
|
39 |
|
40 |
def make_request(URL, headers, data):
|
41 |
response = requests.request("POST", URL, headers=headers, data=data, timeout=(60, 100))
|
requirements.txt
CHANGED
@@ -2,5 +2,4 @@ gradio==4.29.0
|
|
2 |
seaborn
|
3 |
Pillow
|
4 |
matplotlib
|
5 |
-
spacy==3.6.0
|
6 |
requests
|
|
|
2 |
seaborn
|
3 |
Pillow
|
4 |
matplotlib
|
|
|
5 |
requests
|