File size: 1,091 Bytes
6363d82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import os
from utils import process_uploaded_file
from groq_api import ask_groq

st.set_page_config(page_title="Multidoc Chat", layout="wide")

st.title("πŸ“„ Multidoc Chat - Ask Anything About Your Files")

uploaded_file = st.file_uploader("Upload PDF or Excel", type=["pdf", "xlsx"])

if uploaded_file:
    with st.spinner("Processing file..."):
        extracted_text = process_uploaded_file(uploaded_file)

    if "history" not in st.session_state:
        st.session_state.history = []

    st.text_area("Extracted Text Preview", extracted_text[:1000], height=150, disabled=True)

    user_query = st.text_input("Ask something about the document:")

    if st.button("Get Answer") and user_query:
        response = ask_groq(user_query, extracted_text)
        st.session_state.history.append((user_query, response))
    
    if st.session_state.history:
        st.write("### Chat History:")
        for q, a in st.session_state.history:
            st.write(f"**Q:** {q}")
            st.write(f"**A:** {a}")