|
import streamlit as st |
|
from dotenv import load_dotenv |
|
from transformers import pipeline |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") |
|
|
|
def fine_tune_extraction(content, query): |
|
|
|
result = qa_pipeline(question=query, context=content) |
|
return result['answer'] |
|
|
|
def main(): |
|
st.header("Automatic Ticket Classification Tool") |
|
|
|
|
|
st.write("We are here to help you, please ask your question:") |
|
user_input = st.text_input("π") |
|
|
|
if user_input: |
|
try: |
|
|
|
embeddings = create_embeddings() |
|
|
|
|
|
index = pull_from_pinecone( |
|
"pcsk_4etRhj_Lc37c2KWzUgdTSPaShQKgxeZvC331qJcVWjK9LfpDARwkG23kXZoN5ZCHVLyYWZ", |
|
"gcp-starter", |
|
"ticket", |
|
embeddings |
|
) |
|
|
|
|
|
relevant_docs = get_similar_docs(index, user_input) |
|
|
|
|
|
if relevant_docs: |
|
st.write("**Relevant Information:**") |
|
for i, doc in enumerate(relevant_docs, 1): |
|
|
|
content = getattr(doc, "page_content", "No content available.") |
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|