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