Imran08 commited on
Commit
1ddb93c
·
verified ·
1 Parent(s): dff43ae

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +4 -3
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import easyocr
4
+ import os
5
+ import datetime
6
+
7
+ # Initialize OCR reader
8
+ reader = easyocr.Reader(['en', 'hi', 'te', 'ta', 'bn', 'ml', 'gu', 'mr'], gpu=False)
9
+
10
+ # Create a directory to save uploads
11
+ UPLOAD_DIR = "uploaded_data"
12
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
13
+
14
+ st.set_page_config(page_title="Indian Landmark Mapper", layout="centered")
15
+
16
+ st.title("📍 Indian Landmark Mapper")
17
+ st.write("Help preserve India's heritage. Upload a local landmark photo and describe it in your native language.")
18
+
19
+ # File uploader
20
+ image_file = st.file_uploader("Upload a photo of the landmark", type=['jpg', 'jpeg', 'png'])
21
+
22
+ # Text input
23
+ description = st.text_area("Write a short description in your local language")
24
+
25
+ # Optional: OCR toggle
26
+ run_ocr = st.checkbox("Run OCR on uploaded image (optional)")
27
+
28
+ # Optional: Location
29
+ location = st.text_input("Enter location (optional: village, town, district)")
30
+
31
+ # Submission button
32
+ if st.button("Submit"):
33
+ if image_file is None or not description.strip():
34
+ st.warning("Please upload an image and enter a description.")
35
+ else:
36
+ # Save image
37
+ timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
38
+ image_path = os.path.join(UPLOAD_DIR, f"{timestamp}_{image_file.name}")
39
+ with open(image_path, "wb") as f:
40
+ f.write(image_file.getbuffer())
41
+
42
+ # Save metadata
43
+ metadata = {
44
+ "description": description.strip(),
45
+ "location": location,
46
+ "image_filename": image_path,
47
+ "timestamp": timestamp
48
+ }
49
+
50
+ # In real deployment, replace this with saving to Hugging Face dataset or DB
51
+ st.success("✅ Submission received! Thank you for preserving your local heritage.")
52
+ st.json(metadata)
53
+
54
+ # OCR Section
55
+ if image_file and run_ocr:
56
+ st.subheader("🧠 OCR Result")
57
+ img = Image.open(image_file)
58
+ st.image(img, caption="Uploaded Image", use_column_width=True)
59
+
60
+ with st.spinner("Running OCR..."):
61
+ result = reader.readtext(np.array(img))
62
+ extracted_text = "\n".join([line[1] for line in result])
63
+ st.code(extracted_text)
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- altair
2
- pandas
3
- streamlit
 
 
1
+ streamlit
2
+ easyocr
3
+ Pillow
4
+ numpy