Sri-Harsha commited on
Commit
0360a7c
·
verified ·
1 Parent(s): 820ffe4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -31
app.py CHANGED
@@ -1,64 +1,85 @@
1
  import streamlit as st
2
-
3
  import requests
4
  from requests.auth import HTTPBasicAuth
5
  from transformers import pipeline
6
  import json
 
 
 
 
 
 
7
 
8
  # Jira instance details
9
  jira_url = 'https://gen-ai-demo.atlassian.net/'
10
  api_endpoint = '/rest/api/3/search'
11
- username = '[email protected]'
12
  api_token = 'ATATT3xFfGF09uFJnHFeDFU0_AKBZXP98fd2ZFLxzbZfTQ4Tr17IZxD6qoPbniEvLRWsxiO207EAYX77LBfa5NEXiK1J9_Crq7fF1lWPdH8MwY6Vp9GSLr-_0etnMcgqDPRn9cuLD9Lk1IxoxDY_Yh5nm36yp_Xg50RP5AN8mwJmMhC_uoad_A4=CBFBB200'
13
 
14
  # Function to get user input for Jira query using Streamlit
15
  def get_user_input():
16
- summary_keyword = st.text_input("Please give your I/P (e.g., Bug, Authentication issue):")
17
- max_results = st.number_input("Enter number of results to retrieve:", min_value=1, max_value=100, value=5)
18
- return summary_keyword, max_results
19
-
20
- # Streamlit app layout
21
- st.title("Trouble_Ticket_Finder")
22
-
23
- # Get user input through Streamlit widgets
24
- summary_keyword, max_results = get_user_input()
25
 
26
- # If summary keyword is provided, make the Jira API request
27
- if summary_keyword:
28
  # Construct the JQL query based on the user input
29
- jql_query = f'summary ~ "{summary_keyword}"' # Search for issues where summary contains the keyword
30
-
31
- # Construct the API request URL
32
  url = jira_url + api_endpoint
 
 
 
 
 
 
33
 
34
- # Set up the HTTP request headers
35
- headers = {
36
- 'Accept': 'application/json',
37
- 'Content-Type': 'application/json',
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- # Set up the authentication using basic auth (email and API token for Jira Cloud)
41
- auth = HTTPBasicAuth(username, api_token)
42
 
43
- # Define the query parameters
44
- params = {
45
- 'jql': jql_query,
46
- 'maxResults': max_results, # Set max results based on user input
47
- }
48
 
49
- # Send the GET request to Jira API
50
- response = requests.get(url, headers=headers, auth=auth, params=params)
 
51
 
52
  # Check for successful request
53
  if response.status_code == 200:
54
  data = response.json()
55
  issues = data.get('issues', [])
 
56
  if issues:
57
  # If issues are found, display them
 
58
  for issue in issues:
59
  st.write(f"**Key:** {issue['key']} - **Summary:** {issue['fields']['summary']}")
 
60
  else:
61
  st.write("No issues found matching your summary keyword.")
 
 
 
 
 
62
  else:
63
  # If the request failed, show the error details
64
  error_data = response.json()
@@ -66,4 +87,6 @@ if summary_keyword:
66
  if error_message:
67
  st.write(f"Error: {', '.join(error_message)}")
68
  else:
69
- st.write(f"Failed to fetch issues: {response.status_code} - {response.text}")
 
 
 
1
  import streamlit as st
 
2
  import requests
3
  from requests.auth import HTTPBasicAuth
4
  from transformers import pipeline
5
  import json
6
+ from sentence_transformers import SentenceTransformer, util
7
+ from langchain.chains import load_qa_chain
8
+ from langchain.embeddings import SentenceTransformerEmbeddings
9
+ from langchain.vectorstores import FAISS
10
+ from langchain.llms import HuggingFaceEndpoint
11
+ import numpy as np
12
 
13
  # Jira instance details
14
  jira_url = 'https://gen-ai-demo.atlassian.net/'
15
  api_endpoint = '/rest/api/3/search'
16
+ username = '[email protected]'
17
  api_token = 'ATATT3xFfGF09uFJnHFeDFU0_AKBZXP98fd2ZFLxzbZfTQ4Tr17IZxD6qoPbniEvLRWsxiO207EAYX77LBfa5NEXiK1J9_Crq7fF1lWPdH8MwY6Vp9GSLr-_0etnMcgqDPRn9cuLD9Lk1IxoxDY_Yh5nm36yp_Xg50RP5AN8mwJmMhC_uoad_A4=CBFBB200'
18
 
19
  # Function to get user input for Jira query using Streamlit
20
  def get_user_input():
21
+ summary_keyword = st.text_input("Enter summary keyword or phrase (e.g., Bug, Authentication issue):")
22
+ return summary_keyword
 
 
 
 
 
 
 
23
 
24
+ # Function to fetch Jira issues based on the keyword
25
+ def fetch_jira_issues(summary_keyword):
26
  # Construct the JQL query based on the user input
27
+ jql_query = f'summary ~ "{summary_keyword}"'
 
 
28
  url = jira_url + api_endpoint
29
+ headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
30
+ auth = HTTPBasicAuth(username, api_token)
31
+ params = {'jql': jql_query, 'maxResults': 5}
32
+
33
+ response = requests.get(url, headers=headers, auth=auth, params=params)
34
+ return response
35
 
36
+ # Function to load dynamic answer using embeddings-based search
37
+ def load_answer(question):
38
+ embeddings = SentenceTransformerEmbeddings(model_name="nomic-ai/nomic-embed-text-v1", model_kwargs={"trust_remote_code":True})
39
+ # Assuming 'finalData' is a list of documents or text snippets
40
+ finalData = [
41
+ "Authentication failure due to invalid credentials.",
42
+ "Bug in login page causing a crash when incorrect input is provided.",
43
+ "Database timeout issues during large data queries.",
44
+ "Server error due to high request load.",
45
+ "Page rendering issues when javascript fails to load.",
46
+ "Error occurred while fetching data from the API.",
47
+ "Network error caused by unstable connection to the server."
48
+ ]
49
+ documentSearch = FAISS.from_texts(finalData, embeddings)
50
+ chain = load_qa_chain(HuggingFaceEndpoint(repo_id="mistralai/Mistral-7B-Instruct-v0.3"), chain_type="stuff")
51
+ docs = documentSearch.similarity_search(question)
52
+ answer = chain.invoke({"input_documents": docs, "question": question}, return_only_outputs=True)
53
+ return answer
54
 
55
+ # Streamlit app layout
56
+ st.title("Jira Issue Finder with Dynamic Explanations")
57
 
58
+ # Get user input through Streamlit widgets
59
+ summary_keyword = get_user_input()
 
 
 
60
 
61
+ # If summary keyword is provided, make the Jira API request
62
+ if summary_keyword:
63
+ response = fetch_jira_issues(summary_keyword)
64
 
65
  # Check for successful request
66
  if response.status_code == 200:
67
  data = response.json()
68
  issues = data.get('issues', [])
69
+
70
  if issues:
71
  # If issues are found, display them
72
+ st.write("Found Jira issues matching your query:")
73
  for issue in issues:
74
  st.write(f"**Key:** {issue['key']} - **Summary:** {issue['fields']['summary']}")
75
+ st.write(f"**Description:** {issue['fields'].get('description', 'No description available')}")
76
  else:
77
  st.write("No issues found matching your summary keyword.")
78
+
79
+ # If no issues are found, provide dynamic explanation using embeddings
80
+ st.write("Searching for a dynamic explanation using embeddings...")
81
+ answer = load_answer(summary_keyword)
82
+ st.write(f"**Dynamic Explanation:** {answer['output']}")
83
  else:
84
  # If the request failed, show the error details
85
  error_data = response.json()
 
87
  if error_message:
88
  st.write(f"Error: {', '.join(error_message)}")
89
  else:
90
+ st.write(f"Failed to fetch issues: {response.status_code} - {response.text}")
91
+ else:
92
+ st.write("Please enter a summary keyword to search for Jira issues.")