Spaces:
Runtime error
Runtime error
Create app_ui.py
Browse files
app_ui.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
# β
Hugging Face API Endpoints (Using Relative URLs)
|
6 |
+
BACKEND_URL = "https://tejash300-ai-legal-assistant.hf.space"
|
7 |
+
ANALYZE_API_URL = f"{BACKEND_URL}/analyze_legal_document"
|
8 |
+
CHATBOT_API_URL = f"{BACKEND_URL}/chatbot"
|
9 |
+
VIDEO_ANALYZE_API_URL = f"{BACKEND_URL}/analyze_video"
|
10 |
+
|
11 |
+
# β
Configure Streamlit
|
12 |
+
st.set_page_config(page_title="AI-Powered Legal Assistant", layout="wide")
|
13 |
+
|
14 |
+
# β
Sidebar Navigation
|
15 |
+
menu = st.sidebar.radio("π Navigation", ["π Home", "π Legal Document Analyzer", "π₯ Video Analyzer", "π€ Legal Chatbot"])
|
16 |
+
|
17 |
+
if menu == "π Home":
|
18 |
+
st.title("π AI-Powered Legal & Video Assistant")
|
19 |
+
st.markdown("π Welcome to your AI-powered legal and video assistant! Choose an option from the sidebar.")
|
20 |
+
|
21 |
+
elif menu == "π Legal Document Analyzer":
|
22 |
+
st.title("π Legal Document Analyzer")
|
23 |
+
uploaded_file = st.file_uploader("π Upload a PDF document", type=["pdf"])
|
24 |
+
|
25 |
+
if uploaded_file:
|
26 |
+
st.success("β
File uploaded successfully! Analyzing...")
|
27 |
+
|
28 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
|
29 |
+
temp_file.write(uploaded_file.getbuffer())
|
30 |
+
temp_file_path = temp_file.name
|
31 |
+
|
32 |
+
files = {"file": open(temp_file_path, "rb")}
|
33 |
+
try:
|
34 |
+
response = requests.post(ANALYZE_API_URL, files=files, timeout=120)
|
35 |
+
response.raise_for_status()
|
36 |
+
result = response.json()
|
37 |
+
|
38 |
+
# π Document Summary
|
39 |
+
st.subheader("π Document Summary")
|
40 |
+
st.write(result.get("summary", "No summary available."))
|
41 |
+
|
42 |
+
except requests.exceptions.RequestException as e:
|
43 |
+
st.error(f"β API Error: {e}")
|
44 |
+
|
45 |
+
elif menu == "π₯ Video Analyzer":
|
46 |
+
st.title("π¬ Video Content Analyzer")
|
47 |
+
uploaded_video = st.file_uploader("π Upload a Video File", type=["mp4", "avi", "mov"])
|
48 |
+
|
49 |
+
if uploaded_video:
|
50 |
+
st.success("β
Video uploaded successfully! Analyzing...")
|
51 |
+
|
52 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
|
53 |
+
temp_file.write(uploaded_video.getbuffer())
|
54 |
+
temp_file_path = temp_file.name
|
55 |
+
|
56 |
+
files = {"file": open(temp_file_path, "rb")}
|
57 |
+
try:
|
58 |
+
response = requests.post(VIDEO_ANALYZE_API_URL, files=files, timeout=180)
|
59 |
+
response.raise_for_status()
|
60 |
+
result = response.json()
|
61 |
+
|
62 |
+
if result.get("status") == "success":
|
63 |
+
# π Video Transcript
|
64 |
+
st.subheader("π Video Transcript")
|
65 |
+
st.write(result.get("transcript", "No transcript available."))
|
66 |
+
|
67 |
+
else:
|
68 |
+
st.warning("β οΈ No valid data returned from the video analysis API.")
|
69 |
+
|
70 |
+
except requests.exceptions.RequestException as e:
|
71 |
+
st.error(f"β API Error: {e}")
|
72 |
+
|
73 |
+
elif menu == "π€ Legal Chatbot":
|
74 |
+
st.title("π€ AI Legal Chatbot")
|
75 |
+
st.write("π‘ Ask any legal question and get AI-powered responses!")
|
76 |
+
user_query = st.text_input("π¬ Ask a legal question:")
|
77 |
+
|
78 |
+
if st.button("π Get Answer"):
|
79 |
+
if user_query.strip():
|
80 |
+
st.info("β³ Processing your query...")
|
81 |
+
try:
|
82 |
+
response = requests.post(CHATBOT_API_URL, json={"query": user_query}, timeout=60)
|
83 |
+
response.raise_for_status()
|
84 |
+
chatbot_response = response.json().get("answer", "No response available.")
|
85 |
+
st.subheader("π‘ AI's Response")
|
86 |
+
st.success(chatbot_response)
|
87 |
+
except requests.exceptions.RequestException as e:
|
88 |
+
st.error(f"β API Error: {e}")
|
89 |
+
else:
|
90 |
+
st.warning("β οΈ Please enter a question before submitting.")
|