From 7458052d0c3f95da2f24d8bad2fc9e084ed2c1f7 Mon Sep 17 00:00:00 2001 From: CHINU-9 <126506503+CHINU-9@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:47:23 +0530 Subject: [PATCH] Add files via upload --- AI/Task Submission/ChinmayaKumarBehera.txt | 1 + AI/Task Submission/requirements.txt | Bin 0 -> 1708 bytes AI/Task Submission/webapp.py | 70 +++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 AI/Task Submission/ChinmayaKumarBehera.txt create mode 100644 AI/Task Submission/requirements.txt create mode 100644 AI/Task Submission/webapp.py diff --git a/AI/Task Submission/ChinmayaKumarBehera.txt b/AI/Task Submission/ChinmayaKumarBehera.txt new file mode 100644 index 00000000..c5fc6db4 --- /dev/null +++ b/AI/Task Submission/ChinmayaKumarBehera.txt @@ -0,0 +1 @@ +https://github.com/CHINU-9/ai.github.io diff --git a/AI/Task Submission/requirements.txt b/AI/Task Submission/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..07a73275e68c5bc7bd23c95366b25626a4af580d GIT binary patch literal 1708 zcmYk6QE%En5QOi!Qhy3j3~6W|`dq0}rAYk&m19Wi1h8vN2>kfA^X=SWWEmyi-PxJh zz5DmKPMb8QI<;v?U-jIjn>3I2WBQ=)qn;t{BR0>Gn{=CqKB~4&yY!mYxw=y2{iV85 zeUpAGI;Kv~CgXfk#zL=Any4Oy^rROKb4A>%ijK?Z22vedz?-RWr~kJ428;8B1IX|w z=tLWF1o?B0EixjUK&bk!F^<`gxcf`G}t5f)1iu-wV2@1DfP<0k1^{s7EV3u z`7$(4hU2yJnV&0| z%H;X?;Q6B1{DOy~d0@VXKP>indU#xTS7{kYsN(w|XIIKTDt{I_X5w>-eD6`2#E+bP zQ2eLwbQd{Q6b~6j(pVVQ9 zOk-5x1sMh9r2cH7H<$=p>?k|)9P^&G&VIsj%E7gbP`tmW0LS}_Q=ITt?-&k_SKgy( z;#wS?g(qYmRD%m;l5q1Dc>?Dg;Y8!>HP%^kLK{w@kZo<{7n`)#Nnp3ZHCJg!Nni literal 0 HcmV?d00001 diff --git a/AI/Task Submission/webapp.py b/AI/Task Submission/webapp.py new file mode 100644 index 00000000..bf12571d --- /dev/null +++ b/AI/Task Submission/webapp.py @@ -0,0 +1,70 @@ +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) \ No newline at end of file