Spaces:
Sleeping
Sleeping
File size: 4,203 Bytes
141a5de f253970 017fe8f 0360a7c f474742 0360a7c f253970 893e4ea 0360a7c b008cd4 893e4ea cd61cdc 893e4ea e796968 0360a7c 5c28e46 0360a7c 56b3408 0360a7c cd61cdc 0360a7c cd61cdc 0360a7c cd61cdc 0360a7c e796968 cd61cdc 0360a7c cd61cdc 0360a7c cd61cdc 0360a7c cd61cdc 820ffe4 0360a7c cd61cdc 0360a7c cd61cdc 56b3408 0360a7c a97ebe9 a365053 0360a7c |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import streamlit as st
import requests
from requests.auth import HTTPBasicAuth
from transformers import pipeline
import json
from sentence_transformers import SentenceTransformer, util
from langchain.chains.question_answering import load_qa_chain
from langchain_community.embeddings import SentenceTransformerEmbeddings
from langchain_community.vectorstores import FAISS
from langchain.vectorstores import FAISS
from langchain.llms import HuggingFaceEndpoint
import numpy as np
# Jira instance details
jira_url = 'https://gen-ai-demo.atlassian.net/'
api_endpoint = '/rest/api/3/search'
username = '17pa1a0496@vishnu.edu.in'
api_token = 'ATATT3xFfGF09uFJnHFeDFU0_AKBZXP98fd2ZFLxzbZfTQ4Tr17IZxD6qoPbniEvLRWsxiO207EAYX77LBfa5NEXiK1J9_Crq7fF1lWPdH8MwY6Vp9GSLr-_0etnMcgqDPRn9cuLD9Lk1IxoxDY_Yh5nm36yp_Xg50RP5AN8mwJmMhC_uoad_A4=CBFBB200'
# Function to get user input for Jira query using Streamlit
def get_user_input():
summary_keyword = st.text_input("You:")
return summary_keyword
# Function to fetch Jira issues based on the keyword
def fetch_jira_issues(summary_keyword):
# Construct the JQL query based on the user input
jql_query = f'summary ~ "{summary_keyword}"'
url = jira_url + api_endpoint
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
auth = HTTPBasicAuth(username, api_token)
params = {'jql': jql_query, 'maxResults': 5}
response = requests.get(url, headers=headers, auth=auth, params=params)
return response
# Function to load dynamic answer using embeddings-based search
def load_answer(question):
embeddings = SentenceTransformerEmbeddings(model_name="nomic-ai/nomic-embed-text-v1", model_kwargs={"trust_remote_code":True})
# Assuming 'finalData' is a list of documents or text snippets
finalData = [
"Authentication failure due to invalid credentials.",
"Bug in login page causing a crash when incorrect input is provided.",
"Database timeout issues during large data queries.",
"Server error due to high request load.",
"Page rendering issues when javascript fails to load.",
"Error occurred while fetching data from the API.",
"Network error caused by unstable connection to the server."
]
documentSearch = FAISS.from_texts(finalData, embeddings)
chain = load_qa_chain(HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.3"), chain_type="stuff")
docs = documentSearch.similarity_search(question)
answer = chain.invoke({"input_documents": docs, "question": question}, return_only_outputs=True)
return answer
# Streamlit app layout
st.title("Trouble_Ticket_Finder")
# Get user input through Streamlit widgets
summary_keyword = get_user_input()
# If summary keyword is provided, make the Jira API request
if summary_keyword:
response = fetch_jira_issues(summary_keyword)
# Check for successful request
if response.status_code == 200:
data = response.json()
issues = data.get('issues', [])
if issues:
# If issues are found, display them
st.write("Found Jira issues matching your query:")
for issue in issues:
st.write(f"**Key:** {issue['key']} - **Summary:** {issue['fields']['summary']}")
st.write(f"**Description:** {issue['fields'].get('description', 'No description available')}")
else:
st.write("No issues found matching your summary keyword.")
# If no issues are found, provide dynamic explanation using embeddings
st.write("Searching for a dynamic explanation using embeddings...")
answer = load_answer(summary_keyword)
st.write(f"**Dynamic Explanation:** {answer['output']}")
else:
# If the request failed, show the error details
error_data = response.json()
error_message = error_data.get("errorMessages", [])
if error_message:
st.write(f"Error: {', '.join(error_message)}")
else:
st.write(f"Failed to fetch issues: {response.status_code} - {response.text}")
else:
st.write("Please enter a summary keyword to search for Jira issues.") |