Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
from retriever import find_video, build_embeddings
|
5 |
+
|
6 |
+
# Create directories
|
7 |
+
os.makedirs("data/videos", exist_ok=True)
|
8 |
+
os.makedirs("data/machine_catalogs", exist_ok=True)
|
9 |
+
|
10 |
+
st.set_page_config(page_title="Maintenance Knowledge Portal", layout="centered")
|
11 |
+
|
12 |
+
st.title("Maintenance Knowledge Portal")
|
13 |
+
st.markdown("Upload videos, explore catalogs, and ask the AI assistant for help.")
|
14 |
+
|
15 |
+
# --- Upload Section ---
|
16 |
+
st.header("Upload Maintenance Video")
|
17 |
+
video_file = st.file_uploader("Upload Video", type=["mp4", "mov", "avi"])
|
18 |
+
if video_file:
|
19 |
+
with open(os.path.join("data/videos", video_file.name), "wb") as f:
|
20 |
+
f.write(video_file.read())
|
21 |
+
st.success("Video uploaded successfully!")
|
22 |
+
build_embeddings("data/videos") # Update embeddings
|
23 |
+
|
24 |
+
|
25 |
+
st.header("Upload Machine Catalog (PDF)")
|
26 |
+
pdf_file = st.file_uploader("Upload PDF", type=["pdf"])
|
27 |
+
if pdf_file:
|
28 |
+
with open(os.path.join("data/machine_catalogs", pdf_file.name), "wb") as f:
|
29 |
+
f.write(pdf_file.read())
|
30 |
+
st.success("Catalog uploaded!")
|
31 |
+
|
32 |
+
|
33 |
+
# --- Video Viewer Section ---
|
34 |
+
st.header("Available Maintenance Videos")
|
35 |
+
videos = os.listdir("data/videos")
|
36 |
+
if videos:
|
37 |
+
for vid in videos:
|
38 |
+
st.video(os.path.join("data/videos", vid))
|
39 |
+
else:
|
40 |
+
st.info("No videos uploaded yet.")
|
41 |
+
|
42 |
+
|
43 |
+
# --- Catalog Viewer Section ---
|
44 |
+
st.header("Machine Catalogs")
|
45 |
+
catalogs = os.listdir("data/machine_catalogs")
|
46 |
+
if catalogs:
|
47 |
+
for cat in catalogs:
|
48 |
+
st.markdown(f"[{cat}](data/machine_catalogs/{cat})")
|
49 |
+
else:
|
50 |
+
st.info("No catalogs available.")
|
51 |
+
|
52 |
+
|
53 |
+
# --- AI Assistant Section ---
|
54 |
+
st.header("AI Assistant - Ask for Help")
|
55 |
+
user_query = st.text_input("Describe the task or ask about a machine...")
|
56 |
+
if user_query:
|
57 |
+
try:
|
58 |
+
video_file, desc = find_video(user_query)
|
59 |
+
st.subheader("Recommended Video:")
|
60 |
+
st.write(f"**{desc}**")
|
61 |
+
st.video(os.path.join("data/videos", video_file))
|
62 |
+
except Exception as e:
|
63 |
+
st.error("Sorry, couldn't find a matching video. Try uploading more videos.")
|