i want a streamlit app where people can take photo and explain what the problem. The photi must be store in a space or in database and i want add the date and time of the photo. The person can write a little descriptoion (500 words) of the proble. The person is obliged to take his mail
To upload files, please first save the app
import streamlit as st
import sqlite3
from datetime import datetime
import os
from PIL import Image
import base64
import io
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, LargeBinary
from sqlalchemy.orm import DeclarativeBase, Session
# Database setup
class Base(DeclarativeBase):
pass
class ProblemReport(Base):
__tablename__ = 'problem_reports'
id = Column(Integer, primary_key=True)
email = Column(String(255), nullable=False)
description = Column(Text, nullable=False)
photo_data = Column(LargeBinary, nullable=False)
photo_filename = Column(String(255), nullable=False)
timestamp = Column(DateTime, default=datetime.now)
# Create database engine
engine = create_engine("sqlite:///problem_reports.sqlite")
Base.metadata.create_all(bind=engine)
st.title("Problem Reporter")
st.write("Report a problem by taking a photo and providing details")
# Create form
with st.form("problem_report_form"):
st.header("Report Your Problem")
# Email input (required)
email = st.text_input("Email Address *", placeholder="your.email@example.com")
# Photo upload
uploaded_file = st.camera_input("Take a photo of the problem")
# Description input (max 500 words)
description = st.text_area(
"Describe the problem (max 500 words) *",
max_chars=3000, # Roughly 500 words
height=150,
placeholder="Please describe the problem in detail..."
)
# Submit button
submitted = st.form_submit_button("Submit Report")
if submitted:
# Validation
errors = []
if not email:
errors.append("Email address is required")
elif "@" not in email or "." not in email:
errors.append("Please enter a valid email address")
if not uploaded_file:
errors.append("Photo is required")
if not description:
errors.append("Problem description is required")
elif len(description.split()) > 500:
errors.append("Description must be 500 words or less")
if errors:
for error in errors:
st.error(error)
else:
# Process and save the report
try:
# Convert image to binary data
image = Image.open(uploaded_file)
img_buffer = io.BytesIO()
image.save(img_buffer, format='JPEG')
img_binary = img_buffer.getvalue()
# Create new report
report = ProblemReport(
email=email,
description=description,
photo_data=img_binary,
photo_filename=f"photo_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg",
timestamp=datetime.now()
)
# Save to database
with Session(engine) as session:
session.add(report)
session.commit()
st.success("✅ Problem report submitted successfully!")
st.write(f"📧 Email: {email}")
st.write(f"📅 Submitted: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
st.balloons()
except Exception as e:
st.error(f"Error saving report: {str(e)}")
# Display recent reports (optional admin section)
if st.checkbox("Show Recent Reports (Admin)"):
st.header("Recent Problem Reports")
try:
with Session(engine) as session:
reports = session.query(ProblemReport).order_by(ProblemReport.timestamp.desc()).limit(10).all()
if reports:
for report in reports:
with st.expander(f"Report from {report.email} - {report.timestamp.strftime('%Y-%m-%d %H:%M:%S')}"):
st.write(f"**Email:** {report.email}")
st.write(f"**Date:** {report.timestamp.strftime('%Y-%m-%d %H:%M:%S')}")
st.write(f"**Description:** {report.description}")
# Display photo
if report.photo_data:
image = Image.open(io.BytesIO(report.photo_data))
st.image(image, caption=f"Photo: {report.photo_filename}", width=300)
else:
st.write("No reports found.")
except Exception as e:
st.error(f"Error loading reports: {str(e)}")
# Instructions
st.sidebar.header("Instructions")
st.sidebar.write("""
1. **Email**: Enter your email address (required)
2. **Photo**: Take a photo of the problem using your camera
3. **Description**: Describe the problem in detail (max 500 words)
4. **Submit**: Click submit to save your report
Your report will be saved with a timestamp and stored securely in the database.
""")
st.sidebar.header("Tips")
st.sidebar.write("""
- Make sure the photo clearly shows the problem
- Be as detailed as possible in your description
- Include any relevant context or background information
- Your email will be used for follow-up if needed
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?