File size: 2,419 Bytes
c14a846
 
3dd1351
c14a846
3dd1351
 
 
 
c14a846
3dd1351
 
 
 
 
 
 
 
 
c14a846
 
3dd1351
 
 
f574d39
c14a846
3dd1351
 
c14a846
3dd1351
 
 
 
 
c14a846
3dd1351
 
 
c14a846
3dd1351
 
c14a846
3dd1351
 
c14a846
 
39f1c72
c14a846
 
 
 
 
 
 
 
 
39f1c72
 
3dd1351
c14a846
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import requests

# Define Hugging Face API details
API_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer"
API_TOKEN = os.getenv("AUTH_TOKEN")
HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}

# Function to query Hugging Face API
def query_huggingface(payload):
    try:
        response = requests.post(API_URL, headers=HEADERS, json=payload)
        response.raise_for_status()  # Raise exception for non-2xx status codes
        return response.json()
    except requests.exceptions.RequestException as e:
        st.error(f"Error querying Hugging Face API: {e}")
        return {"summary_text": f"Error querying Hugging Face API: {e}"}


def main():
    
    st.set_page_config(layout="centered")
    st.title("Chat Summarizer")

    # User input for chat message
    user_message = st.text_input("User Message", "Enter your message here...")

    # Process user input and query Hugging Face API
    if st.button("Summarize"):
        if user_message:
            # Construct input text for summarization (no system message)
            input_text = f"User: {user_message}"

            # Query Hugging Face API for summarization
            payload = {"inputs": input_text}
            response = query_huggingface(payload)

            # Extract summary text from the API response
            summary_text = response.get("summary_text", "")

            # Display summary text
            st.text_area("Summary", value=summary_text)

    with st.sidebar:
        
        st.header("Chat with PDF")
        # st.title("Menu:")
        pdf_docs = st.file_uploader("Upload your PDF Files and Click on the Submit Button", accept_multiple_files=True, type=["pdf"])
        if st.button("Submit"):
            with st.spinner("Processing..."):
                raw_text = get_pdf_text(pdf_docs)
                text_chunks = get_text_chunks(raw_text)
                get_vector_store(text_chunks, api_key)
                st.success("Done")
        
        if st.button("Chat Summarizer"):
            st.switch_page('app.py')
    # Check if any document is uploaded
    if pdf_docs:
        user_question = st.text_input("Ask a question from the Docs")
        if user_question:
            user_input(user_question, api_key)
    else:
        st.write("Please upload a document first to ask questions.")
           
if __name__ == "__main__":
    main()