Spaces:
Sleeping
Sleeping
Commit
·
d7977f2
1
Parent(s):
36e82c7
updates scoping
Browse files
app.py
CHANGED
@@ -33,27 +33,30 @@ fig =''
|
|
33 |
output_string = ''
|
34 |
|
35 |
|
36 |
-
def prompt_analyze_reporting(prompt):
|
37 |
-
|
|
|
|
|
|
|
38 |
data_structure_overview},
|
39 |
{"role": "user", "content":
|
40 |
data_relationships_overview},{"role": "user", "content":
|
41 |
f"""Do not attempt to use .csv files in your code."""},
|
42 |
{"role": "user", "content":
|
43 |
-
f"""Only use plotly to output charts, graphs, or figures. Do not use matplotlib or other charting libraries. Name the chart object as 'fig'"""},
|
44 |
{"role": "user", "content":
|
45 |
f"""Create a python script to: {prompt}"""}
|
46 |
-
|
47 |
-
global parsed_response
|
48 |
parsed_response = output.choices[0].message.content.strip().split('```python')[len(output.choices[0].message.content.strip().split('```python')) -1 ].split('```')[0]
|
49 |
-
|
50 |
-
|
51 |
-
{parsed_response}"""
|
52 |
-
exec(parsed_response_global)
|
53 |
return fig
|
54 |
|
55 |
-
def prompt_analyze_questions(prompt):
|
56 |
-
|
|
|
|
|
|
|
57 |
data_structure_overview},
|
58 |
{"role": "user", "content":
|
59 |
data_relationships_overview},{"role": "user", "content":
|
@@ -68,18 +71,38 @@ def prompt_analyze_questions(prompt):
|
|
68 |
f"""Store the final response as a string variable named output_string"""}
|
69 |
])
|
70 |
|
71 |
-
global parsed_response
|
72 |
parsed_response = output.choices[0].message.content.strip().split('```python')[len(output.choices[0].message.content.strip().split('```python')) -1 ].split('```')[0]
|
73 |
-
|
74 |
-
|
75 |
-
{parsed_response}
|
76 |
-
globals().update(locals())"""
|
77 |
-
exec(parsed_response_global)
|
78 |
return output_string
|
79 |
|
80 |
# Data Retrieval
|
81 |
|
82 |
def getData(tlspc_api_key, openai_api_key):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
try:
|
84 |
# Store OpenAI API Key
|
85 |
openai.api_key = openai_api_key
|
@@ -199,30 +222,6 @@ def getData(tlspc_api_key, openai_api_key):
|
|
199 |
|
200 |
machine_identities_df.drop(['companyId'],axis=1,inplace=True)
|
201 |
|
202 |
-
# Certificate Requests
|
203 |
-
def getCertRequests():
|
204 |
-
currentPage = 0
|
205 |
-
cert_requests_url = "https://api.venafi.cloud/outagedetection/v1/certificaterequestssearch"
|
206 |
-
headers = {
|
207 |
-
"accept": "application/json",
|
208 |
-
"tppl-api-key": tlspc_api_key}
|
209 |
-
payload = { "paging": {
|
210 |
-
"pageNumber": 1,
|
211 |
-
"pageSize": 1000}}
|
212 |
-
response = requests.post(url=cert_requests_url, headers=headers,json=payload)
|
213 |
-
if(response.status_code != 200):
|
214 |
-
raise Exception('Error retrieving certificate requests:' + "\n" + response.text + "\n=============\n")
|
215 |
-
data = response.json()
|
216 |
-
cert_requests = data['certificateRequests']
|
217 |
-
while data['numFound'] > (currentPage * 1000):
|
218 |
-
currentPage+=1
|
219 |
-
print('Getting page ' + str(currentPage) + ': Number remaining - ' + str(data['numFound'] - currentPage*1000))
|
220 |
-
payload['paging']['pageNumber'] = currentPage
|
221 |
-
response = requests.post(url=cert_requests_url, headers=headers,json=payload)
|
222 |
-
data = response.json()
|
223 |
-
cert_requests += data['certificateRequests']
|
224 |
-
return cert_requests
|
225 |
-
|
226 |
cert_requests_json = getCertRequests()
|
227 |
cert_requests_df = pd.json_normalize(cert_requests_json).convert_dtypes()
|
228 |
cert_requests_df.rename(columns = {'id':'cert_request_id', 'creationDate':'cert_request_creationDate'}, inplace = True)
|
@@ -275,11 +274,13 @@ def getData(tlspc_api_key, openai_api_key):
|
|
275 |
The column values in the 'certificateOwnerUserId' column in cert_requests_df match the column values in the 'user_id' column in users_df.
|
276 |
The column values in the 'certificateIssuingTemplateId' column in certs_request_df match the column values in the 'issuing_template_id' column in issuing_templates_df.
|
277 |
"""
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
283 |
|
284 |
except:
|
285 |
|
@@ -322,10 +323,10 @@ with gr.Blocks(theme='aliabid94/new-theme') as demo:
|
|
322 |
chart_button = gr.Button("Submit")
|
323 |
gr.Markdown("<sup><sub>Reminder: This is an experimental project to test new capabilities. Take care and understand risks of using API keys and accessing data especially if running from Hugging Face. Rotate keys after use.</sup></sub>")
|
324 |
|
|
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
load_button.click(getData, inputs=[tlspc_api_key, openai_api_key], outputs=api_key_output)
|
330 |
|
331 |
demo.launch()
|
|
|
33 |
output_string = ''
|
34 |
|
35 |
|
36 |
+
def prompt_analyze_reporting(prompt, passed_args):
|
37 |
+
data_structure_overview = passed_args['data_structure_overview']
|
38 |
+
data_relationships_overview = passed_args['data_relationships_overview']
|
39 |
+
passed_args['fig'] = ''
|
40 |
+
output = openai.ChatCompletion.create(model="gpt-3.5-turbo",temperature = 0.0, messages=[{"role": "user", "content":
|
41 |
data_structure_overview},
|
42 |
{"role": "user", "content":
|
43 |
data_relationships_overview},{"role": "user", "content":
|
44 |
f"""Do not attempt to use .csv files in your code."""},
|
45 |
{"role": "user", "content":
|
46 |
+
f"""Only use plotly to output charts, graphs, or figures. Do not use matplotlib or other charting libraries. Name the chart object as 'fig' but do not show it"""},
|
47 |
{"role": "user", "content":
|
48 |
f"""Create a python script to: {prompt}"""}
|
49 |
+
])
|
|
|
50 |
parsed_response = output.choices[0].message.content.strip().split('```python')[len(output.choices[0].message.content.strip().split('```python')) -1 ].split('```')[0]
|
51 |
+
exec(parsed_response,globals(),passed_args)
|
52 |
+
fig = passed_args['fig']
|
|
|
|
|
53 |
return fig
|
54 |
|
55 |
+
def prompt_analyze_questions(prompt, passed_args):
|
56 |
+
data_structure_overview = passed_args['data_structure_overview']
|
57 |
+
data_relationships_overview = passed_args['data_relationships_overview']
|
58 |
+
passed_args['output_string']=''
|
59 |
+
output = openai.ChatCompletion.create(model="gpt-3.5-turbo",temperature = 0.0, messages=[{"role": "user", "content":
|
60 |
data_structure_overview},
|
61 |
{"role": "user", "content":
|
62 |
data_relationships_overview},{"role": "user", "content":
|
|
|
71 |
f"""Store the final response as a string variable named output_string"""}
|
72 |
])
|
73 |
|
|
|
74 |
parsed_response = output.choices[0].message.content.strip().split('```python')[len(output.choices[0].message.content.strip().split('```python')) -1 ].split('```')[0]
|
75 |
+
exec(parsed_response,globals(),passed_args)
|
76 |
+
output_string = passed_args['output_string']
|
|
|
|
|
|
|
77 |
return output_string
|
78 |
|
79 |
# Data Retrieval
|
80 |
|
81 |
def getData(tlspc_api_key, openai_api_key):
|
82 |
+
#Get Cert Requests
|
83 |
+
def getCertRequests():
|
84 |
+
currentPage = 0
|
85 |
+
cert_requests_url = "https://api.venafi.cloud/outagedetection/v1/certificaterequestssearch"
|
86 |
+
headers = {
|
87 |
+
"accept": "application/json",
|
88 |
+
"tppl-api-key": tlspc_api_key}
|
89 |
+
payload = {"paging": {
|
90 |
+
"pageNumber": 1,
|
91 |
+
"pageSize": 1000}}
|
92 |
+
response = requests.post(url=cert_requests_url, headers=headers, json=payload)
|
93 |
+
if (response.status_code != 200):
|
94 |
+
raise Exception('Error retrieving certificate requests:' + "\n" + response.text + "\n=============\n")
|
95 |
+
data = response.json()
|
96 |
+
cert_requests = data['certificateRequests']
|
97 |
+
while data['numFound'] > (currentPage * 1000):
|
98 |
+
currentPage += 1
|
99 |
+
print('Getting page ' + str(currentPage) + ': Number remaining - ' + str(
|
100 |
+
data['numFound'] - currentPage * 1000))
|
101 |
+
payload['paging']['pageNumber'] = currentPage
|
102 |
+
response = requests.post(url=cert_requests_url, headers=headers, json=payload)
|
103 |
+
data = response.json()
|
104 |
+
cert_requests += data['certificateRequests']
|
105 |
+
return cert_requests
|
106 |
try:
|
107 |
# Store OpenAI API Key
|
108 |
openai.api_key = openai_api_key
|
|
|
222 |
|
223 |
machine_identities_df.drop(['companyId'],axis=1,inplace=True)
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
cert_requests_json = getCertRequests()
|
226 |
cert_requests_df = pd.json_normalize(cert_requests_json).convert_dtypes()
|
227 |
cert_requests_df.rename(columns = {'id':'cert_request_id', 'creationDate':'cert_request_creationDate'}, inplace = True)
|
|
|
274 |
The column values in the 'certificateOwnerUserId' column in cert_requests_df match the column values in the 'user_id' column in users_df.
|
275 |
The column values in the 'certificateIssuingTemplateId' column in certs_request_df match the column values in the 'issuing_template_id' column in issuing_templates_df.
|
276 |
"""
|
277 |
+
passed_args = {'application_df': application_df, 'users_df': users_df, 'certs_df': certs_df,
|
278 |
+
'teams_df': teams_df, 'machines_df': machines_df, 'machine_identities_df': machine_identities_df,
|
279 |
+
'cert_requests_df': cert_requests_df, 'issuing_templates_df': issuing_templates_df,
|
280 |
+
'data_structure_overview': data_structure_overview,
|
281 |
+
'data_relationships_overview': data_relationships_overview}
|
282 |
+
|
283 |
+
return 'Data successfully loaded!', passed_args
|
284 |
|
285 |
except:
|
286 |
|
|
|
323 |
chart_button = gr.Button("Submit")
|
324 |
gr.Markdown("<sup><sub>Reminder: This is an experimental project to test new capabilities. Take care and understand risks of using API keys and accessing data especially if running from Hugging Face. Rotate keys after use.</sup></sub>")
|
325 |
|
326 |
+
passed_args = gr.State([])
|
327 |
|
328 |
+
text_button.click(prompt_analyze_questions, inputs=[prompt_questions,passed_args], outputs=text_output)
|
329 |
+
chart_button.click(prompt_analyze_reporting, inputs=[prompt_reporting,passed_args], outputs=chart_output)
|
330 |
+
load_button.click(getData, inputs=[tlspc_api_key, openai_api_key], outputs=[api_key_output,passed_args])
|
|
|
331 |
|
332 |
demo.launch()
|