File size: 1,522 Bytes
f3dfbd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import sys
import os

# Add the project root to Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.config import validate_config
from app.logging import setup_logging

def main():
    # Setup logging
    setup_logging()
    
    st.set_page_config(
        page_title="CRE Knowledge Assistant",
        page_icon="🤖",
        layout="wide"
    )

    st.title("CRE Knowledge Assistant")
    
    # File uploader
    uploaded_file = st.file_uploader("Upload a PDF document", type="pdf")
    
    if uploaded_file:
        # Convert file to bytes
        file_bytes = uploaded_file.getvalue()
        
        # Send to API endpoint
        response = requests.post(
            "api/process_pdf",
            files={"file": (uploaded_file.name, file_bytes, "application/pdf")}
        )
        
        if response.status_code == 200:
            st.success("PDF processed successfully!")
        else:
            st.error("Error processing PDF")
    
    # Query input
    query = st.text_input("Ask a question about your documents:")
    
    if query:
        # Send query to API endpoint
        response = requests.post(
            "api/query",
            json={"query": query}
        )
        
        if response.status_code == 200:
            result = response.json()
            st.write("Answer:", result["answer"])
        else:
            st.error("Error processing query")

if __name__ == "__main__":
    main()