update format image and send score
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ gmt_plus7 = pytz.timezone('Etc/GMT-7') # 'Etc/GMT-7' represents GMT+7
|
|
30 |
|
31 |
def authenticate(user_id):
|
32 |
|
33 |
-
url = "https://intern-api.imtaedu.com/api/subnets/
|
34 |
headers = {
|
35 |
"Content-Type": "application/json",
|
36 |
"Accept": "application/json",
|
@@ -44,20 +44,21 @@ def authenticate(user_id):
|
|
44 |
def login(username, state, package):
|
45 |
state[0] = username
|
46 |
#package[0] = get_next_package(user_id=username)
|
47 |
-
|
48 |
#temp
|
49 |
gr.Info("Login successfully. Welcome!")
|
50 |
return f"Welcome, {username}!", gr.update(visible=False), gr.update(visible=True)
|
51 |
#temp
|
52 |
-
|
|
|
53 |
# Authenticate user
|
54 |
if authenticate(username):
|
55 |
#user_sessions[username] = True
|
56 |
gr.Info("Login successfully. Welcome!")
|
57 |
-
return gr.update(visible=False), gr.update(visible=True)
|
58 |
else:
|
59 |
-
raise gr.Error("
|
60 |
-
return "Invalid
|
61 |
|
62 |
def logout(username):
|
63 |
# Log out user and reset session
|
@@ -72,7 +73,7 @@ def get_image_bytes(image):
|
|
72 |
|
73 |
# Convert the image to bytes
|
74 |
img_byte_arr = io.BytesIO()
|
75 |
-
image.save(img_byte_arr, format='
|
76 |
img_bytes = img_byte_arr.getvalue()
|
77 |
|
78 |
return img_bytes
|
@@ -106,7 +107,7 @@ def process_image_and_caption(username_input, image, caption):
|
|
106 |
# Create a byte array buffer (like a binary file stream)
|
107 |
byte_buffer = io.BytesIO(caption_bytes)
|
108 |
upload_caption_result = cloudinary.uploader.upload(byte_buffer, public_id = name, asset_folder = "caption", resource_type = "raw")
|
109 |
-
|
110 |
gr.Info("Submit successfully")
|
111 |
return f'You just upload an Image with Caption: "{caption}" \nIntime {time}', None, None
|
112 |
|
|
|
30 |
|
31 |
def authenticate(user_id):
|
32 |
|
33 |
+
url = "https://intern-api.imtaedu.com/api/subnets/2/authenticate"
|
34 |
headers = {
|
35 |
"Content-Type": "application/json",
|
36 |
"Accept": "application/json",
|
|
|
44 |
def login(username, state, package):
|
45 |
state[0] = username
|
46 |
#package[0] = get_next_package(user_id=username)
|
47 |
+
"""
|
48 |
#temp
|
49 |
gr.Info("Login successfully. Welcome!")
|
50 |
return f"Welcome, {username}!", gr.update(visible=False), gr.update(visible=True)
|
51 |
#temp
|
52 |
+
"""
|
53 |
+
|
54 |
# Authenticate user
|
55 |
if authenticate(username):
|
56 |
#user_sessions[username] = True
|
57 |
gr.Info("Login successfully. Welcome!")
|
58 |
+
return f"Welcome, {username}!", gr.update(visible=False), gr.update(visible=True)
|
59 |
else:
|
60 |
+
raise gr.Error("Token ID is invalid! Try again!")
|
61 |
+
return "Invalid Token ID", gr.update(visible=True), gr.update(visible=False)
|
62 |
|
63 |
def logout(username):
|
64 |
# Log out user and reset session
|
|
|
73 |
|
74 |
# Convert the image to bytes
|
75 |
img_byte_arr = io.BytesIO()
|
76 |
+
image.save(img_byte_arr, format='JPEG') # Save as PNG or desired format
|
77 |
img_bytes = img_byte_arr.getvalue()
|
78 |
|
79 |
return img_bytes
|
|
|
107 |
# Create a byte array buffer (like a binary file stream)
|
108 |
byte_buffer = io.BytesIO(caption_bytes)
|
109 |
upload_caption_result = cloudinary.uploader.upload(byte_buffer, public_id = name, asset_folder = "caption", resource_type = "raw")
|
110 |
+
send_score(username_input, 0.1)
|
111 |
gr.Info("Submit successfully")
|
112 |
return f'You just upload an Image with Caption: "{caption}" \nIntime {time}', None, None
|
113 |
|