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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -62
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import streamlit as st
2
- import numpy as np
3
  import requests
4
  from requests.auth import HTTPBasicAuth
5
  from transformers import pipeline
6
  import json
7
- from sentence_transformers import SentenceTransformer, util
8
 
9
  # Jira instance details
10
  jira_url = 'https://gen-ai-demo.atlassian.net/'
@@ -14,36 +13,18 @@ api_token = 'ATATT3xFfGF09uFJnHFeDFU0_AKBZXP98fd2ZFLxzbZfTQ4Tr17IZxD6qoPbniEvLRW
14
 
15
  # Function to get user input for Jira query using Streamlit
16
  def get_user_input():
17
- summary_keyword = st.text_input("You:")
18
  max_results = st.number_input("Enter number of results to retrieve:", min_value=1, max_value=100, value=5)
19
  return summary_keyword, max_results
20
 
21
- # Function to find similar issues using embeddings
22
- def find_similar_issues(summary_keyword, jira_issues):
23
- model = SentenceTransformer('all-MiniLM-L6-v2')
24
-
25
- # Create embeddings for the input summary
26
- query_embedding = model.encode(summary_keyword, convert_to_tensor=True)
27
-
28
- if not jira_issues:
29
- # If no issues from Jira, return an empty list or fallback options
30
- st.write("No issues found in Jira. Using fallback dataset for embedding search.")
31
- return []
32
-
33
- # Create embeddings for the issue summaries
34
- issue_summaries = [issue['fields']['summary'] for issue in jira_issues]
35
- issue_embeddings = model.encode(issue_summaries, convert_to_tensor=True)
36
-
37
- # Calculate cosine similarities between the input summary and the issue summaries
38
- similarities = util.pytorch_cos_sim(query_embedding, issue_embeddings)[0]
39
 
40
- # Get top N most similar issues
41
- top_results = np.argsort(similarities, axis=0)[-5:][::-1]
42
-
43
- return [(jira_issues[i]['key'], jira_issues[i]['fields']['summary'], similarities[i].item()) for i in top_results]
44
 
45
- # Function to fetch Jira issues
46
- def fetch_jira_issues(summary_keyword, max_results):
47
  # Construct the JQL query based on the user input
48
  jql_query = f'summary ~ "{summary_keyword}"' # Search for issues where summary contains the keyword
49
 
@@ -68,50 +49,16 @@ def fetch_jira_issues(summary_keyword, max_results):
68
  # Send the GET request to Jira API
69
  response = requests.get(url, headers=headers, auth=auth, params=params)
70
 
71
- return response
72
-
73
- # Streamlit app layout
74
- st.title("Trouble_Ticket_Finder")
75
-
76
- # Get user input through Streamlit widgets
77
- summary_keyword, max_results = get_user_input()
78
-
79
- # If summary keyword is provided, make the Jira API request
80
- if summary_keyword:
81
- # Fetch Jira issues based on summary keyword
82
- response = fetch_jira_issues(summary_keyword, max_results)
83
-
84
  # Check for successful request
85
  if response.status_code == 200:
86
  data = response.json()
87
  issues = data.get('issues', [])
88
-
89
  if issues:
90
- # If issues are found in Jira, display them
91
- st.write("Found Jira issues matching the summary keyword:")
92
  for issue in issues:
93
  st.write(f"**Key:** {issue['key']} - **Summary:** {issue['fields']['summary']}")
94
- # Provide general elaboration of the issue (could be description or other fields)
95
- st.write(f"**Description:** {issue['fields'].get('description', 'No description available')}")
96
  else:
97
  st.write("No issues found matching your summary keyword.")
98
-
99
- # If no issues are found in Jira, try to find similar issues based on embeddings
100
- st.write("Searching for similar issues using embeddings...")
101
-
102
- # If issues are empty, this will prevent the error and just return an empty list
103
- similar_issues = find_similar_issues(summary_keyword, issues) # This uses the Jira issues
104
-
105
- if similar_issues:
106
- st.write("Similar Issues found using embeddings:")
107
- for key, summary, similarity in similar_issues:
108
- st.write(f"**Similar Issue Key:** {key}")
109
- st.write(f"**Summary:** {summary}")
110
- st.write(f"**Similarity Score:** {similarity:.4f}")
111
- # Provide general elaboration of the similar issue
112
- st.write(f"**Elaboration:** The similarity score indicates how closely this issue matches the input summary.")
113
- else:
114
- st.write("No similar issues found using embeddings.")
115
  else:
116
  # If the request failed, show the error details
117
  error_data = response.json()
 
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/'
 
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
 
 
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()