-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
72 lines (58 loc) · 2.29 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import asyncio
import aioboto3
import time
import os
import qrcode
async def main():
image = st.camera_input("Please take a picture")
if image is not None:
# st.image(image, caption="Captured Image.")
session = aioboto3.Session()
bucket = os.environ.get("R2_BUCKET_NAME")
s3_endpoint = os.environ.get("R2_S3_ENDPOINT")
access_key = os.environ.get("R2_ACCESS_KEY_ID")
secret_key = os.environ.get("R2_SECRET_ACCESS_KEY")
domain = "https://void.meetups.city"
async with session.client(
"s3",
endpoint_url=s3_endpoint,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
) as s3:
# unix timestamp
timestamp = int(time.time())
Key = f"gdgchennai/camera/{timestamp}.jpg"
await s3.put_object(Bucket=bucket, Key=Key, Body=image.getvalue())
image_url = f"{domain}/{Key}"
# st.image(image_url, caption="Uploaded Image here from cdn")
# create qr code
qr_code_image = qrcode.make(image_url)
# convert to byte stream
qr_code_image = qr_code_image._img.convert("RGB")
# https://void-ui.meetups.city/1722524058
st.image(qr_code_image, caption="QR Code Image")
st.download_button(
label="Download Image",
data=image.getvalue(),
file_name=f"{timestamp}.jpg",
mime="image/jpeg",
)
save_to_local(image=image, qr_image=qr_code_image, timestamp=timestamp)
def save_to_local(image, qr_image, timestamp):
# Define the directory path using the timestamp
directory = f"image_dump/{timestamp}"
# Ensure the directory exists
if not os.path.exists(directory):
os.makedirs(directory)
# Define the file paths for the image and QR code
image_path = os.path.join(directory, "image.jpg")
qr_image_path = os.path.join(directory, "qr_image.jpg")
# Save the image
with open(image_path, "wb") as img_file:
img_file.write(image.getvalue())
# Save the QR code image
qr_image.save(qr_image_path)
print(f"Images saved to {directory}")
if __name__ == "__main__":
asyncio.run(main())