Prathamesh1420's picture
Create app.py
9fd14cb verified
raw
history blame
2.01 kB
import streamlit as st
import os
import shutil
from retriever import find_video, build_embeddings
# Create directories
os.makedirs("data/videos", exist_ok=True)
os.makedirs("data/machine_catalogs", exist_ok=True)
st.set_page_config(page_title="Maintenance Knowledge Portal", layout="centered")
st.title("Maintenance Knowledge Portal")
st.markdown("Upload videos, explore catalogs, and ask the AI assistant for help.")
# --- Upload Section ---
st.header("Upload Maintenance Video")
video_file = st.file_uploader("Upload Video", type=["mp4", "mov", "avi"])
if video_file:
with open(os.path.join("data/videos", video_file.name), "wb") as f:
f.write(video_file.read())
st.success("Video uploaded successfully!")
build_embeddings("data/videos") # Update embeddings
st.header("Upload Machine Catalog (PDF)")
pdf_file = st.file_uploader("Upload PDF", type=["pdf"])
if pdf_file:
with open(os.path.join("data/machine_catalogs", pdf_file.name), "wb") as f:
f.write(pdf_file.read())
st.success("Catalog uploaded!")
# --- Video Viewer Section ---
st.header("Available Maintenance Videos")
videos = os.listdir("data/videos")
if videos:
for vid in videos:
st.video(os.path.join("data/videos", vid))
else:
st.info("No videos uploaded yet.")
# --- Catalog Viewer Section ---
st.header("Machine Catalogs")
catalogs = os.listdir("data/machine_catalogs")
if catalogs:
for cat in catalogs:
st.markdown(f"[{cat}](data/machine_catalogs/{cat})")
else:
st.info("No catalogs available.")
# --- AI Assistant Section ---
st.header("AI Assistant - Ask for Help")
user_query = st.text_input("Describe the task or ask about a machine...")
if user_query:
try:
video_file, desc = find_video(user_query)
st.subheader("Recommended Video:")
st.write(f"**{desc}**")
st.video(os.path.join("data/videos", video_file))
except Exception as e:
st.error("Sorry, couldn't find a matching video. Try uploading more videos.")