File size: 2,380 Bytes
d3d39e7
 
30dff6f
d3d39e7
30dff6f
 
27569fb
30dff6f
 
 
 
 
 
 
 
 
27569fb
793190e
 
27569fb
 
 
 
793190e
30dff6f
793190e
 
 
 
 
 
 
 
 
 
 
 
 
6a153ca
 
 
 
163f9ae
 
6a153ca
30dff6f
88974cc
6a153ca
88974cc
 
 
 
 
6a153ca
 
 
 
 
793190e
6a153ca
 
793190e
20f2d79
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
import streamlit as st
from dotenv import load_dotenv
from transformers import pipeline

# Load environment variables
load_dotenv()

# Initialize the question-answering pipeline with a pre-trained model
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

def fine_tune_extraction(content, query):
    # Use the pipeline to answer the question using the document content
    result = qa_pipeline(question=query, context=content)
    return result['answer']

def main():
    st.header("Automatic Ticket Classification Tool")
    
    # Capture user input
    st.write("We are here to help you, please ask your question:")
    user_input = st.text_input("πŸ”")

    if user_input:
        try:
            # Assuming create_embeddings and pull_from_pinecone are defined elsewhere
            embeddings = create_embeddings()

            # Fetch the Pinecone index using the API key and environment info
            index = pull_from_pinecone(
                "pcsk_4etRhj_Lc37c2KWzUgdTSPaShQKgxeZvC331qJcVWjK9LfpDARwkG23kXZoN5ZCHVLyYWZ",
                "gcp-starter",
                "ticket",
                embeddings
            )

            # Fetch the relevant documents based on the user input
            relevant_docs = get_similar_docs(index, user_input)

            # Process and display relevant documents
            if relevant_docs:
                st.write("**Relevant Information:**")
                for i, doc in enumerate(relevant_docs, 1):
                    # Access the document content directly
                    content = getattr(doc, "page_content", "No content available.")  # Safely access content

                    # Apply fine-tuned extraction model to extract relevant information
                    relevant_info = fine_tune_extraction(content, user_input)

                    if relevant_info:
                        st.write(f"**Document {i}:**")
                        st.write(f"```{relevant_info}...```")
                    else:
                        st.write(f"**Document {i}:** No relevant information found.")
            else:
                st.write("No relevant documents found.")

        except Exception as e:
            st.write(f"An error occurred while processing your request: {e}")


# Ensure proper script execution entry point
if __name__ == "__main__":
    main()