dwipper commited on
Commit
fa4d5f0
·
1 Parent(s): fb105c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -25
app.py CHANGED
@@ -126,7 +126,7 @@ def get_schools():
126
 
127
  return schools
128
 
129
- def get_sports ():
130
 
131
  airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{sports_table_name}'
132
 
@@ -156,7 +156,7 @@ def get_sports ():
156
  # Print the list of 'school' values
157
  # print(sports)
158
  else:
159
- print("No records found in the 'policies' table.")
160
  else:
161
  print(f"Failed to retrieve school data. Status code: {response.status_code}")
162
  except Exception as e:
@@ -164,6 +164,44 @@ def get_sports ():
164
 
165
  return sports
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  def get_prompt(header, template_content):
168
 
169
  airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{prompts_table_name}'
@@ -275,6 +313,9 @@ def chatbot(school_selection,gender,social_media_channel,sports,interests,output
275
 
276
  trimmed_input = prompt_trim(analysis_input)
277
 
 
 
 
278
  response = openai.ChatCompletion.create(
279
  model="gpt-4",
280
  #model="gpt-3.5-turbo",
@@ -299,17 +340,20 @@ def chatbot(school_selection,gender,social_media_channel,sports,interests,output
299
  prompt_tokens = tokens_used.get('prompt_tokens',)
300
  completion_tokens = tokens_used.get('completion_tokens', 0)
301
 
 
 
 
302
  end_time = datetime.datetime.now()
303
 
304
  response_time = end_time - start_time
305
 
306
- global scout_response
307
 
308
  scout_response = gpt_response
309
 
310
  append_to_at_scountlog(school_selection, output_format, gender,interests,sports,gpt_response,number_of_athletes,social_media_channel,response_time,question_cost,prompt_tokens,completion_tokens)
311
 
312
- return response_label,gpt_response
313
 
314
  def log_login(username):
315
 
@@ -326,7 +370,7 @@ def log_login(username):
326
  }
327
  try:
328
 
329
- # Post data to Airtable
330
  response = requests.post(airtable_endpoint, headers=headers, json=data)
331
 
332
  # Check for errors
@@ -374,9 +418,10 @@ school_selection = []
374
 
375
  schools = get_schools()
376
  sports = get_sports()
 
377
 
378
  get_examples()
379
-
380
  logged_in_user = 'admin'
381
 
382
  with gr.Blocks(CIMStheme) as iface:
@@ -389,26 +434,41 @@ with gr.Blocks(CIMStheme) as iface:
389
  gr.Markdown("")
390
  with gr.Row():
391
  with gr.Column():
392
- gr.Interface(fn=chatbot,
393
- inputs=[
394
- gr.components.Dropdown(schools,multiselect=True,info="Select one or more schools. This will select avaliable Student Athletes from the school(s)",label="School Selection"),
395
- gr.components.Dropdown(["Male","Female"],multiselect=True,info="Select one or more.",label="Gender"),
396
- gr.components.Dropdown(["Facebook","Instagram","TikTok","X (Twitter)","YouTube","SnapChat","Twitch"],multiselect=True,info="Select one or more.",label="Social Media Channel"),
397
- gr.components.Dropdown(sports,multiselect=True,info="Select one or more.",label="Sports"),
398
- gr.components.Dropdown(["Fashion","Sports","Food","Cooking","Travel","Arts","Music"],multiselect=True,info="Select one or more.",label="Interests"),
399
- gr.components.Dropdown(["Summary","Detailed Analysis","Table"],multiselect=False,info="Select the desired output format.",label="Output Format"),
400
- gr.components.Dropdown(["1","2","3","4","5","6","7","8","9","10"],multiselect=False,info="How many athletes are you looking for?",label="Number of Athletes")],
401
- outputs=[
402
- gr.components.Markdown(response_label),
403
- gr.components.HTML(label="Scout Response")
404
- ],
405
- description="Use Scout to find and rank Athletes that meet your criteria",
406
- allow_flagging="never",
407
- cache_examples=False
408
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  with gr.Row():
410
  with gr.Column():
411
  gr.HTML('<center><i>CIMS.AI Confidential 2023</i></center>')
412
 
413
- iface.launch(auth=login_auth, auth_message= "Enter your username and password that you received from CIMS.AI. To request a login, please email 'info@cims.ai'",share=True)
414
- #iface.launch()
 
126
 
127
  return schools
128
 
129
+ def get_sports():
130
 
131
  airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{sports_table_name}'
132
 
 
156
  # Print the list of 'school' values
157
  # print(sports)
158
  else:
159
+ print("No records found in the 'schools' table.")
160
  else:
161
  print(f"Failed to retrieve school data. Status code: {response.status_code}")
162
  except Exception as e:
 
164
 
165
  return sports
166
 
167
+ def get_interests():
168
+
169
+ airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{interests_table_name}'
170
+
171
+ # Parameters for the API request to select only the 'interest' field
172
+ params = {
173
+ 'fields[]': 'interest', # Replace with the name of your field
174
+ 'sort[0][field]': 'interest', # Sort by the 'school' field
175
+ 'sort[0][direction]': 'asc', # Sort in ascending order
176
+ }
177
+
178
+ interests = ''
179
+
180
+ try:
181
+ # Send a GET request to the Airtable API
182
+ response = requests.get(airtable_endpoint, headers=headers, params=params)
183
+
184
+ # Check if the request was successful (status code 200)
185
+ if response.status_code == 200:
186
+ # Parse the JSON response
187
+ data = response.json()
188
+
189
+ # Check if there are records in the response
190
+ if data.get('records'):
191
+ # Extract the 'school' values from each record
192
+ interests = [record['fields']['interest'] for record in data['records']]
193
+
194
+ else:
195
+ print("No records found in the 'interests' table.")
196
+ else:
197
+ print(f"Failed to retrieve interest data. Status code: {response.status_code}")
198
+ except Exception as e:
199
+ print(f"An error occurred: {str(e)}")
200
+
201
+ return interests
202
+
203
+
204
+
205
  def get_prompt(header, template_content):
206
 
207
  airtable_endpoint = f'https://api.airtable.com/v0/{base_id}/{prompts_table_name}'
 
313
 
314
  trimmed_input = prompt_trim(analysis_input)
315
 
316
+ with open('analysis_input.txt', 'w', encoding='utf-8') as out_file:
317
+ out_file.write(trimmed_input)
318
+
319
  response = openai.ChatCompletion.create(
320
  model="gpt-4",
321
  #model="gpt-3.5-turbo",
 
340
  prompt_tokens = tokens_used.get('prompt_tokens',)
341
  completion_tokens = tokens_used.get('completion_tokens', 0)
342
 
343
+ with open('response.txt', 'w', encoding='utf-8') as out_file:
344
+ out_file.write(gpt_response)
345
+
346
  end_time = datetime.datetime.now()
347
 
348
  response_time = end_time - start_time
349
 
350
+ #global scout_response
351
 
352
  scout_response = gpt_response
353
 
354
  append_to_at_scountlog(school_selection, output_format, gender,interests,sports,gpt_response,number_of_athletes,social_media_channel,response_time,question_cost,prompt_tokens,completion_tokens)
355
 
356
+ return scout_response
357
 
358
  def log_login(username):
359
 
 
370
  }
371
  try:
372
 
373
+ # Post data to Airtable
374
  response = requests.post(airtable_endpoint, headers=headers, json=data)
375
 
376
  # Check for errors
 
418
 
419
  schools = get_schools()
420
  sports = get_sports()
421
+ interests = get_interests()
422
 
423
  get_examples()
424
+ scout_response = ''
425
  logged_in_user = 'admin'
426
 
427
  with gr.Blocks(CIMStheme) as iface:
 
434
  gr.Markdown("")
435
  with gr.Row():
436
  with gr.Column():
437
+ school_selection=gr.components.Dropdown(schools,multiselect=True,info="Select one or more schools. This will select avaliable Student Athletes from the school(s)",label="School Selection")
438
+ with gr.Column():
439
+ gender=gr.components.Dropdown(["Male","Female"],multiselect=True,info="Select one or more.",label="Gender")
440
+ with gr.Column():
441
+ social_media_channel=gr.components.Dropdown(["Facebook","Instagram","TikTok","X (Twitter)","YouTube","SnapChat","Twitch"],multiselect=True,info="Select one or more.",label="Social Media Channel")
442
+ with gr.Row():
443
+ with gr.Column():
444
+ sports=gr.components.Dropdown(sports,multiselect=True,info="Select one or more.",label="Sports")
445
+ with gr.Column():
446
+ interests=gr.components.Dropdown(interests,multiselect=True,info="Select one or more.",label="Interests")
447
+ with gr.Column():
448
+ number_of_athletes=gr.components.Dropdown(["1","2","3","4","5","6","7","8","9","10"],multiselect=False,info="How many athletes are you looking for?",label="Number of Athletes")
449
+ with gr.Row():
450
+ with gr.Column():
451
+ output_format=gr.components.Dropdown(["Summary","Detailed Analysis","Table"],multiselect=False,info="Select the desired output format.",label="Output Format")
452
+ with gr.Column():
453
+ gr.Markdown("")
454
+ with gr.Column():
455
+ gr.Markdown("")
456
+ with gr.Row():
457
+ with gr.Column():
458
+ btn = gr.components.Button(value="Submit",size='sm')
459
+ with gr.Column():
460
+ gr.Markdown("")
461
+ with gr.Column():
462
+ gr.Markdown("")
463
+ with gr.Row():
464
+ with gr.Column():
465
+ gr.components.Markdown(response_label)
466
+ with gr.Row():
467
+ with gr.Column():
468
+ scout_response = gr.components.HTML(value="",label="response")
469
+ btn.click(chatbot, inputs=[school_selection,gender,social_media_channel,sports,interests,output_format,number_of_athletes], outputs=[scout_response])
470
  with gr.Row():
471
  with gr.Column():
472
  gr.HTML('<center><i>CIMS.AI Confidential 2023</i></center>')
473
 
474
+ iface.launch(auth=login_auth, auth_message= "Enter your username and password that you received from CIMS.AI. To request a login, please email 'info@cims.ai'")