Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,65 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
x = st.slider('Select a value')
|
4 |
-
st.write(x, 'squared is', x * x)
|
|
|
1 |
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import base64
|
4 |
+
import io
|
5 |
+
import time
|
6 |
+
from PIL import Image
|
7 |
+
import random
|
8 |
+
|
9 |
+
# Initialize session state for tokens
|
10 |
+
if "tokens" not in st.session_state:
|
11 |
+
st.session_state.tokens = 0
|
12 |
+
|
13 |
+
# Page title
|
14 |
+
st.title("📷 Food Crowdsourcing Research App")
|
15 |
+
|
16 |
+
st.write("Help our research by uploading food images! Earn tokens for future app use.")
|
17 |
+
|
18 |
+
# Upload image
|
19 |
+
uploaded_file = st.file_uploader("Upload a food image", type=["jpg", "png", "jpeg"])
|
20 |
+
|
21 |
+
# Terms and Conditions
|
22 |
+
st.markdown("### **Terms & Conditions**")
|
23 |
+
st.write(
|
24 |
+
"By uploading an image, you agree to transfer full copyright to the research team for AI training purposes. "
|
25 |
+
"You are responsible for ensuring you own the image and it does not violate any copyright laws. "
|
26 |
+
"We do not guarantee when tokens will be redeemable. Keep track of your user ID.")
|
27 |
+
st.checkbox("I agree to the terms and conditions", key="terms_accepted")
|
28 |
+
|
29 |
+
# Process image
|
30 |
+
if uploaded_file and st.session_state.terms_accepted:
|
31 |
+
image = Image.open(uploaded_file)
|
32 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
33 |
+
|
34 |
+
# Show original size
|
35 |
+
st.write(f"Original size: {image.size}")
|
36 |
+
|
37 |
+
# Convert PNG to JPEG if needed
|
38 |
+
if image.format == "PNG":
|
39 |
+
image = image.convert("RGB")
|
40 |
+
|
41 |
+
# Resize image to max 1024x1024 px
|
42 |
+
MAX_SIZE = (1024, 1024)
|
43 |
+
image.thumbnail(MAX_SIZE)
|
44 |
+
|
45 |
+
# Convert image to bytes
|
46 |
+
img_bytes = io.BytesIO()
|
47 |
+
image.save(img_bytes, format="JPEG", quality=80) # Reduce quality to save space
|
48 |
+
img_bytes.seek(0)
|
49 |
+
|
50 |
+
# Show resized size
|
51 |
+
st.write(f"New size: {image.size}")
|
52 |
+
|
53 |
+
# Upload to S3 (Simulated API Call)
|
54 |
+
# response = requests.post("YOUR_BACKEND_API/upload", files={"file": img_bytes.getvalue()})
|
55 |
+
|
56 |
+
# Token rewards system
|
57 |
+
st.session_state.tokens += 1 # 1 Token for uploading
|
58 |
+
st.write("✅ You earned **1 token** for uploading!")
|
59 |
+
|
60 |
+
# Future: Add annotation for an extra token
|
61 |
+
# st.session_state.tokens += 1 # If annotation is provided
|
62 |
+
|
63 |
+
st.success(f"Total tokens: {st.session_state.tokens}")
|
64 |
+
|
65 |
|
|
|
|