LilRg commited on
Commit
07663af
·
verified ·
1 Parent(s): 161ac77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import json
3
  import gradio as gr
4
  import logging
5
  import re
 
6
 
7
  logging.basicConfig(level=logging.ERROR)
8
  logger = logging.getLogger(__name__)
@@ -22,6 +23,52 @@ competence_questions = [
22
  "Quelles sont vos compétences en gestion de projet ?"
23
  ]
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def get_last_user_id():
26
  url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"
27
  headers = {
@@ -340,8 +387,10 @@ def manage_conversation_flow(question, response, history):
340
  skill_assessment = call_api_for_skill_assessment(all_responses)
341
  return f"Désolé, nous avons rencontré un problème. Voici votre bilan basé sur les informations fournies :\n\n{skill_assessment}", skill_assessment
342
 
343
- def submit_and_compare(skill_assessment_output):
344
- student_id, student_name, student_mail = get_last_user_id()
 
 
345
  airtable_response = upload_to_airtable(skill_assessment_output, student_id)
346
 
347
  enterprise_descriptions = get_enterprise_descriptions()
@@ -426,7 +475,7 @@ with gr.Blocks(theme=custom_theme) as demo:
426
  lines=5
427
  )
428
  gr.Markdown(
429
- """<a href="https://felice1519.softr.app" target="_blank">
430
  <button style="width: 100%; padding: 10px; background-color: #C4DAFB; color: #3662E3; border: none; border-radius: 5px; font-family: 'Helvetica', sans-serif; font-weight: bold;">
431
  🔮 Voir offres 🔮
432
  </button>
 
3
  import gradio as gr
4
  import logging
5
  import re
6
+ from gradio import Request
7
 
8
  logging.basicConfig(level=logging.ERROR)
9
  logger = logging.getLogger(__name__)
 
23
  "Quelles sont vos compétences en gestion de projet ?"
24
  ]
25
 
26
+
27
+ def getParams(x, request: gr.Request):
28
+ params = request.query_params
29
+
30
+ if 'name' in params:
31
+ return params['name']
32
+ else:
33
+ return None
34
+
35
+
36
+
37
+ def get_id_by_name(student_name):
38
+ url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"
39
+ headers = {
40
+ "Authorization": f"Bearer {AIRTABLE_API_KEY}",
41
+ "Content-Type": "application/json"
42
+ }
43
+
44
+ # Filtrer les enregistrements par ID_Etu
45
+ params = {
46
+ "filterByFormula": f"FIND('{student_name}', {{Nom}})"
47
+ }
48
+
49
+ try:
50
+ response = requests.get(url, headers=headers, params=params)
51
+
52
+ if response.status_code == 200:
53
+ data = response.json()
54
+
55
+ if len(data['records']) > 0:
56
+ record = data['records'][0] # On prend le premier enregistrement correspondant
57
+ student_id = record['fields'].get('ID_Etu', 'Aucun id trouvé')
58
+ user_email = record['fields'].get('Email', 'Aucun email trouvé')
59
+ return student_id, user_email
60
+ else:
61
+ return None, None
62
+ else:
63
+ logger.error(f"Erreur lors de la récupération des informations : {response.status_code} - {response.text}")
64
+ return None, None
65
+
66
+ except Exception as e:
67
+ logger.error(f"Erreur lors de la récupération des informations : {str(e)}")
68
+ return None, None
69
+
70
+
71
+
72
  def get_last_user_id():
73
  url = f"https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/Inscription_Etudiants"
74
  headers = {
 
387
  skill_assessment = call_api_for_skill_assessment(all_responses)
388
  return f"Désolé, nous avons rencontré un problème. Voici votre bilan basé sur les informations fournies :\n\n{skill_assessment}", skill_assessment
389
 
390
+ def submit_and_compare(skill_assessment_output, request: gr.Request):
391
+ student_name = getParams(None, request)
392
+ student_id, student_mail = get_id_by_name(student_name)
393
+ #student_id, student_name, student_mail = get_last_user_id()
394
  airtable_response = upload_to_airtable(skill_assessment_output, student_id)
395
 
396
  enterprise_descriptions = get_enterprise_descriptions()
 
475
  lines=5
476
  )
477
  gr.Markdown(
478
+ """<a href="https://albatrossstudent.softr.app" target="_blank">
479
  <button style="width: 100%; padding: 10px; background-color: #C4DAFB; color: #3662E3; border: none; border-radius: 5px; font-family: 'Helvetica', sans-serif; font-weight: bold;">
480
  🔮 Voir offres 🔮
481
  </button>