From 9d12e544be62d5d5085f4f82069207eb037d4b7f Mon Sep 17 00:00:00 2001 From: Shreeti Mohapatra <114981873+shivah12@users.noreply.github.com> Date: Thu, 13 Apr 2023 01:04:05 +0530 Subject: [PATCH] Add files via upload --- AI/Task Submission/Shreeti Mohapatra.txt | 1 + AI/Task Submission/requirements.txt | Bin 0 -> 1708 bytes AI/Task Submission/webapp.py | 71 +++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 AI/Task Submission/Shreeti Mohapatra.txt create mode 100644 AI/Task Submission/requirements.txt create mode 100644 AI/Task Submission/webapp.py diff --git a/AI/Task Submission/Shreeti Mohapatra.txt b/AI/Task Submission/Shreeti Mohapatra.txt new file mode 100644 index 00000000..b6ed5ae2 --- /dev/null +++ b/AI/Task Submission/Shreeti Mohapatra.txt @@ -0,0 +1 @@ +https://github.com/shivah12/AI-ML.github.io \ No newline at end of file diff --git a/AI/Task Submission/requirements.txt b/AI/Task Submission/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..cbfe498ec2b1d02583d1d8a223d9ef9466a9d64b GIT binary patch literal 1708 zcmYk6QE%En5QOi!Qhy3j3`uAo`dq0}C8Yje`lp1QP8-}Kz2n>3F1bNZz3gPwglL~NWRH|aJJeN=6iw&^u3b9JN22faWGsZ*<_t90BlvTIRW8K@kIreQ4Ez|fPGjNJ zO5caHkYmMTVom1wJ)$!q405X%0$D}JB%jl%ek-OWb{7mgG3VU9YEk+qXEx!`T>13R z6?CO~{v&w4C^r7UL(w=eU&J34hul3pF1(vG4J1_YeJ^Jh%04N76go!YbB=t^QR&3b zoPAXMm;QbdOHj$GXK#dd6zV!+cB$~%DuP<0yTQ~Y4I(7CFmNf_0)SxFC5saPVW#74p-iz zsd6ojj=~eNkE+3i(n+{^irj%qjW8asGZls*eHa6$l zTY5|9iB|>aus7vCv^&;E-+Z=j8g`w{q8?tQl6!_*W|e-6!@JI5>QUmIC7)@p6ENs@ zyuJ&3zt(OL=N_a3=1aXh*d$FP7$XU=<>FC Q*Gk4kDt6g(BF&YG|90&4SpWb4 literal 0 HcmV?d00001 diff --git a/AI/Task Submission/webapp.py b/AI/Task Submission/webapp.py new file mode 100644 index 00000000..5ff5833d --- /dev/null +++ b/AI/Task Submission/webapp.py @@ -0,0 +1,71 @@ +import streamlit as st +import numpy as np +from PIL import Image +import cv2 +import tempfile +import os + +# Define the app layout +st.title("Image and Video Captioning App") +menu = ["Image", "Video"] +choice = st.sidebar.selectbox("Select an option", menu) + +# Define the capture mode +mode = st.sidebar.radio("Select capture mode", ["Local file", "Camera"]) + +tfile = None # initialize tfile variable to None + +# Define the file upload option +if mode == "Local file": + file = st.file_uploader("Upload file", type=[choice.lower(), "mp4", "avi"]) + if file is not None: + tfile = tempfile.NamedTemporaryFile(delete=False) + tfile.write(file.read()) + +# Define the camera capture option +else: + cap = cv2.VideoCapture(0) + if st.button("Capture"): + # Capture the frame + ret, img = cap.read() + # Save the frame to a temporary file + tfile = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") + cv2.imwrite(tfile.name, cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) + cap.release() + +# Define the caption input +caption = st.text_input("Enter a caption") + +# Display the image/video with caption +if tfile is not None: + st.write(f"**{caption}**") + if choice == "Image": + img = Image.open(tfile.name) + st.image(img) + else: + st.video(tfile.name) + + +st.title("Image Upload") + +# Display file upload widget +uploaded_file = st.file_uploader("Choose an image...", type="jpg") + +# Display caption input box +caption = st.text_input('Enter a caption for the image (optional):') + +# If a file was uploaded +if uploaded_file is not None: + # Read the file contents + image = Image.open(uploaded_file) + st.image(image, caption=caption, use_column_width=True) + img_array = np.array(image) + + # Write the file to a temporary file + with tempfile.NamedTemporaryFile(delete=False) as tfile: + tfile.write(img_array) + st.write('Image saved to:', tfile.name) + + # Close the file and delete + os.unlink(tfile.name) +