Spaces:
Sleeping
Sleeping
refined app structure with appointment toggle
Browse files- app.py +115 -117
- requirements.txt +2 -1
app.py
CHANGED
@@ -5,12 +5,12 @@ import uuid
|
|
5 |
import streamlit as st
|
6 |
from azure.cosmos import CosmosClient
|
7 |
from datetime import datetime, timedelta
|
8 |
-
from ParamClasses import CreateParams, AppointmentDBItem, Attendee
|
9 |
from dotenv import load_dotenv
|
10 |
|
11 |
load_dotenv()
|
12 |
|
13 |
-
def create_meeting(input_params
|
14 |
try:
|
15 |
url = f"{os.environ.get('BASE_API')}/api/create-appointment"
|
16 |
response = requests.post(url=url,data=input_params)
|
@@ -19,18 +19,7 @@ def create_meeting(input_params: CreateParams) -> dict:
|
|
19 |
except Exception as e:
|
20 |
print(f"Fehler beim erstellen des Termins: {str(e)}")
|
21 |
st.error("Something went wrong, please contact the site admin.", icon="π¨")
|
22 |
-
|
23 |
-
def get_summary(input_params) -> dict:
|
24 |
-
print(input_params)
|
25 |
-
try:
|
26 |
-
url = f"{os.environ.get('BASE_API')}/api/create-interview-summary"
|
27 |
-
response = requests.post(url=url,data=input_params)
|
28 |
-
response.raise_for_status()
|
29 |
-
return response.json()
|
30 |
-
except Exception as e:
|
31 |
-
print(f"Fehler beim erstellen des Termins: {str(e)}")
|
32 |
-
st.error(f"Something went wrong: {str(e)}", icon="π¨")
|
33 |
-
|
34 |
def adjust_datetime(original_datetime_str, offset_option):
|
35 |
# Konvertiere den originalen DateTime-String in ein datetime-Objekt
|
36 |
original_datetime = datetime.strptime(original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
@@ -58,27 +47,117 @@ def adjust_datetime(original_datetime_str, offset_option):
|
|
58 |
adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
59 |
return adjusted_datetime_str
|
60 |
|
61 |
-
def
|
62 |
-
print("hitesttest")
|
63 |
try:
|
64 |
-
st.session_state["cosmos_db"]
|
|
|
|
|
|
|
65 |
except Exception as e:
|
66 |
-
print(f"Fehler beim erstellen des DB items: {str(e)}")
|
67 |
st.error("Something went wrong, please contact the site admin.", icon="π¨")
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
if "appointment_response" not in st.session_state:
|
71 |
st.session_state["appointment_response"] = None
|
72 |
-
if "subject_input" not in st.session_state:
|
73 |
-
st.session_state["subject_input"] = None
|
74 |
if "cosmos_db" not in st.session_state:
|
75 |
# Cosmos DB Client erstellen
|
76 |
client = CosmosClient(os.environ.get('DB_CONNECTION'), os.environ.get('DB_KEY'))
|
77 |
-
|
78 |
-
# Datenbank und Container referenzieren
|
79 |
-
database = client.get_database_client(os.environ.get('DB_NAME'))
|
80 |
-
container = database.get_container_client(os.environ.get('DB_CONTAINER'))
|
81 |
-
st.session_state["cosmos_db"] = container
|
82 |
|
83 |
col1, col2 = st.columns([2, 1])
|
84 |
|
@@ -87,100 +166,19 @@ col2.image("https://www.workgenius.com/wp-content/uploads/2023/03/WorkGenius_nav
|
|
87 |
|
88 |
st.write("Please enter the date, time and duration for the appointment to be created.")
|
89 |
|
90 |
-
|
91 |
now = datetime.now()
|
92 |
rounded_now = now + timedelta(minutes=30 - now.minute % 30)
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
# recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
|
98 |
# client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
|
99 |
# candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")
|
|
|
|
|
100 |
|
101 |
-
if
|
102 |
-
|
103 |
-
|
104 |
-
if subject_input:
|
105 |
-
start_date_utc_str = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
106 |
-
print(start_date_utc_str)
|
107 |
-
start_date_str = adjust_datetime(start_date_utc_str, st.session_state["time_option"])
|
108 |
-
print(start_date_str)
|
109 |
-
end_date = datetime.strptime(str(selected_date)+" "+str(selected_time),"%Y-%m-%d %H:%M:%S") + timedelta(minutes=selected_duration)
|
110 |
-
end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
111 |
-
end_date_str = adjust_datetime(end_date_utc_str, st.session_state["time_option"])
|
112 |
-
with st.spinner("Creating the appointment..."):
|
113 |
-
request_params = json.dumps({
|
114 |
-
"appointment": {
|
115 |
-
"start_time": start_date_str,
|
116 |
-
"end_time": end_date_str
|
117 |
-
},
|
118 |
-
"subject": subject_input,
|
119 |
-
"recruiter": {
|
120 |
-
"email": "",#st.session_state["recruiter_mail"],
|
121 |
-
"name": ""#st.session_state["recruiter_mail"]
|
122 |
-
},
|
123 |
-
"client": {
|
124 |
-
"email": "",#st.session_state["client_mail"],
|
125 |
-
"name": ""#st.session_state["client_mail"]
|
126 |
-
},
|
127 |
-
"candidate": {
|
128 |
-
"email": "",#st.session_state["candidate_mail"],
|
129 |
-
"name": ""#st.session_state["candidate_mail"]
|
130 |
-
}
|
131 |
-
})
|
132 |
-
appointment_response = create_meeting(request_params)
|
133 |
-
# appointment_response = False
|
134 |
-
# st.write(appointment_response)
|
135 |
-
if appointment_response:
|
136 |
-
|
137 |
-
st.success("The appointment was created correctly.")
|
138 |
-
st.write(appointment_response["zoom_meeting"]["start_url"])
|
139 |
-
db_item = AppointmentDBItem(
|
140 |
-
id=str(uuid.uuid4()),
|
141 |
-
zoom_meeting_id=str(appointment_response["zoom_meeting"]["id"]),
|
142 |
-
process_id=str(uuid.uuid4()),
|
143 |
-
job_title=subject_input,
|
144 |
-
start_time=start_date_str,
|
145 |
-
end_time=end_date_str,
|
146 |
-
meeting_url=appointment_response["zoom_meeting"]["start_url"],
|
147 |
-
environment=str(["us"]),
|
148 |
-
process_status="interview_scheduled",
|
149 |
-
recruiter=Attendee(
|
150 |
-
email="",#str(st.session_state["recruiter_mail"]),
|
151 |
-
name=""#str(st.session_state["recruiter_mail"])
|
152 |
-
),
|
153 |
-
client=Attendee(
|
154 |
-
email="",#str(st.session_state["client_mail"]),
|
155 |
-
name=""#str(st.session_state["client_mail"])
|
156 |
-
),
|
157 |
-
candidate=Attendee(
|
158 |
-
email="",#str(st.session_state["candidate_mail"]),
|
159 |
-
name=""#str(st.session_state["candidate_mail"])
|
160 |
-
),
|
161 |
-
summary_recruiter="",
|
162 |
-
summary_client="",
|
163 |
-
summary_candidate=""
|
164 |
-
)
|
165 |
-
write_appointment_db_object(db_item)
|
166 |
-
st.info("Once you have attended the meeting and it has ended, please wait about 10 minutes before requesting the meeting recording as it will take time to become available ", icon="βΉοΈ")
|
167 |
-
st.session_state["appointment_response"] = appointment_response
|
168 |
-
print(appointment_response["zoom_meeting"]["id"])
|
169 |
-
st.session_state["subject_input"] = subject_input
|
170 |
-
if st.button("Create Interview Summary"):
|
171 |
-
print("please")
|
172 |
-
print(st.session_state["appointment_response"]["zoom_meeting"]["id"])
|
173 |
-
st.rerun()
|
174 |
-
# print("nach btn summary")
|
175 |
-
# with st.spinner("Creating the summary..."):
|
176 |
-
# summary_response = get_summary({"interview_subject": subject_input})
|
177 |
-
# if summary_response:
|
178 |
-
# st.write(summary_response)
|
179 |
-
|
180 |
-
else:
|
181 |
-
st.warning("Please enter the subject of the meeting")
|
182 |
-
else:
|
183 |
-
with st.spinner("Creating the summary..."):
|
184 |
-
summary_response = get_summary(json.dumps({"meeting_id": str(st.session_state["appointment_response"]["zoom_meeting"]["id"])}))
|
185 |
-
#summary_response = get_summary(json.dumps({"meeting_id": str(85662554678)}))
|
186 |
-
st.write(summary_response)
|
|
|
5 |
import streamlit as st
|
6 |
from azure.cosmos import CosmosClient
|
7 |
from datetime import datetime, timedelta
|
8 |
+
from ParamClasses import CreateParams, AppointmentDBItem, Attendee, Appointment
|
9 |
from dotenv import load_dotenv
|
10 |
|
11 |
load_dotenv()
|
12 |
|
13 |
+
def create_meeting(input_params) -> dict:
|
14 |
try:
|
15 |
url = f"{os.environ.get('BASE_API')}/api/create-appointment"
|
16 |
response = requests.post(url=url,data=input_params)
|
|
|
19 |
except Exception as e:
|
20 |
print(f"Fehler beim erstellen des Termins: {str(e)}")
|
21 |
st.error("Something went wrong, please contact the site admin.", icon="π¨")
|
22 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def adjust_datetime(original_datetime_str, offset_option):
|
24 |
# Konvertiere den originalen DateTime-String in ein datetime-Objekt
|
25 |
original_datetime = datetime.strptime(original_datetime_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
|
|
47 |
adjusted_datetime_str = adjusted_datetime.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
48 |
return adjusted_datetime_str
|
49 |
|
50 |
+
def write_interview_db_object(interview_data):
|
|
|
51 |
try:
|
52 |
+
db_client: CosmosClient = st.session_state["cosmos_db"]
|
53 |
+
database = db_client.get_database_client("appointment-database")
|
54 |
+
container = database.get_container_client("appointments")
|
55 |
+
container.create_item(body=interview_data)
|
56 |
except Exception as e:
|
57 |
+
print(f"Fehler beim erstellen des Appointment DB items: {str(e)}")
|
58 |
st.error("Something went wrong, please contact the site admin.", icon="π¨")
|
59 |
|
60 |
+
def write_assessment_db_object(interview_data):
|
61 |
+
try:
|
62 |
+
db_client: CosmosClient = st.session_state["cosmos_db"]
|
63 |
+
database = db_client.get_database_client("assessment-database")
|
64 |
+
container = database.get_container_client("assessments")
|
65 |
+
print(interview_data)
|
66 |
+
container.create_item(body=interview_data)
|
67 |
+
except Exception as e:
|
68 |
+
print(f"Fehler beim erstellen des Assessment DB items: {str(e)}")
|
69 |
+
st.error("Something went wrong, please contact the site admin.", icon="π¨")
|
70 |
+
|
71 |
+
def create_button_handler():
|
72 |
+
with st.spinner("Creating the appointment..."):
|
73 |
+
start_date_utc_str = datetime.strptime(str(st.session_state["date_input"])+" "+str(st.session_state["time_input"]),"%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
74 |
+
start_date_str = adjust_datetime(start_date_utc_str, st.session_state["time_zone_option"])
|
75 |
+
end_date = datetime.strptime(str(st.session_state["date_input"])+" "+str(st.session_state["time_input"]),"%Y-%m-%d %H:%M:%S") + timedelta(minutes=st.session_state["duration_input"])
|
76 |
+
end_date_utc_str = end_date.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
77 |
+
end_date_str = adjust_datetime(end_date_utc_str, st.session_state["time_zone_option"])
|
78 |
+
request_params = json.dumps({
|
79 |
+
"appointment": {
|
80 |
+
"start_time": start_date_str,
|
81 |
+
"end_time": end_date_str
|
82 |
+
},
|
83 |
+
"subject": st.session_state["subject_input"],
|
84 |
+
"recruiter": {
|
85 |
+
"email": "",#st.session_state["recruiter_mail"],
|
86 |
+
"name": ""#st.session_state["recruiter_mail"]
|
87 |
+
},
|
88 |
+
"client": {
|
89 |
+
"email": "",#st.session_state["client_mail"],
|
90 |
+
"name": ""#st.session_state["client_mail"]
|
91 |
+
},
|
92 |
+
"candidate": {
|
93 |
+
"email": "",#st.session_state["candidate_mail"],
|
94 |
+
"name": ""#st.session_state["candidate_mail"]
|
95 |
+
}
|
96 |
+
})
|
97 |
+
appointment_response = create_meeting(request_params)
|
98 |
+
st.session_state["appointment_response"] = appointment_response
|
99 |
+
if st.session_state["assessment_toggle"]:
|
100 |
+
db_item = {
|
101 |
+
"id":str(uuid.uuid4()),
|
102 |
+
"zoom_meeting_id":str(appointment_response["zoom_meeting"]["id"]),
|
103 |
+
"assessment_title":st.session_state["subject_input"],
|
104 |
+
"start_time":start_date_str,
|
105 |
+
"end_time":end_date_str,
|
106 |
+
"meeting_url":appointment_response["zoom_meeting"]["start_url"],
|
107 |
+
"environment":str(["us"]),
|
108 |
+
"process_status":"assessment_scheduled",
|
109 |
+
"recruiter": {
|
110 |
+
"email": "",#str(st.session_state["recruiter_mail"]),
|
111 |
+
"name": ""#str(st.session_state["recruiter_mail"])
|
112 |
+
},
|
113 |
+
"client": {
|
114 |
+
"email": "",#str(st.session_state["client_mail"]),
|
115 |
+
"name": ""#str(st.session_state["client_mail"])
|
116 |
+
},
|
117 |
+
"candidate": {
|
118 |
+
"email": "",#str(st.session_state["candidate_mail"]),
|
119 |
+
"name": ""#str(st.session_state["candidate_mail"])
|
120 |
+
},
|
121 |
+
"interview_transcript": "",
|
122 |
+
"questions": [],
|
123 |
+
"coding_tasks": []
|
124 |
+
}
|
125 |
+
write_assessment_db_object(db_item)
|
126 |
+
else:
|
127 |
+
db_item = {
|
128 |
+
"id":str(uuid.uuid4()),
|
129 |
+
"zoom_meeting_id":str(appointment_response["zoom_meeting"]["id"]),
|
130 |
+
"process_id":str(uuid.uuid4()),
|
131 |
+
"job_title":st.session_state["subject_input"],
|
132 |
+
"start_time":start_date_str,
|
133 |
+
"end_time":end_date_str,
|
134 |
+
"meeting_url":appointment_response["zoom_meeting"]["start_url"],
|
135 |
+
"environment":str(["us"]),
|
136 |
+
"process_status":"interview_scheduled",
|
137 |
+
"recruiter": {
|
138 |
+
"email": "",#str(st.session_state["recruiter_mail"]),
|
139 |
+
"name": ""#str(st.session_state["recruiter_mail"])
|
140 |
+
},
|
141 |
+
"client": {
|
142 |
+
"email": "",#str(st.session_state["client_mail"]),
|
143 |
+
"name": ""#str(st.session_state["client_mail"])
|
144 |
+
},
|
145 |
+
"candidate": {
|
146 |
+
"email": "",#str(st.session_state["candidate_mail"]),
|
147 |
+
"name": ""#str(st.session_state["candidate_mail"])
|
148 |
+
},
|
149 |
+
"summary_recruiter":"",
|
150 |
+
"summary_client":"",
|
151 |
+
"summary_candidate":""
|
152 |
+
}
|
153 |
+
write_interview_db_object(db_item)
|
154 |
+
|
155 |
if "appointment_response" not in st.session_state:
|
156 |
st.session_state["appointment_response"] = None
|
|
|
|
|
157 |
if "cosmos_db" not in st.session_state:
|
158 |
# Cosmos DB Client erstellen
|
159 |
client = CosmosClient(os.environ.get('DB_CONNECTION'), os.environ.get('DB_KEY'))
|
160 |
+
st.session_state["cosmos_db"] = client
|
|
|
|
|
|
|
|
|
161 |
|
162 |
col1, col2 = st.columns([2, 1])
|
163 |
|
|
|
166 |
|
167 |
st.write("Please enter the date, time and duration for the appointment to be created.")
|
168 |
|
169 |
+
st.date_input("Date of the appointment",format="DD/MM/YYYY", key="date_input")
|
170 |
now = datetime.now()
|
171 |
rounded_now = now + timedelta(minutes=30 - now.minute % 30)
|
172 |
+
st.time_input("Starting time of the appointment", value=rounded_now, key="time_input")
|
173 |
+
st.selectbox("Please select your time zone (based on UTC time)",options=["+10","+9","+8","+7","+6","+5","+4","+3","+2","+1","0","-1","-2","-3","-4","-5","-6","-7","-8","-9","-10"],index=10, key="time_zone_option")
|
174 |
+
st.select_slider("Duration of the appointment in minutes",[15,30,45,60],value=30, key="duration_input")
|
175 |
+
st.text_input("Enter the subject of the meeting", key="subject_input")
|
176 |
# recruiter_mail = st.text_input("Please enter the mail of the recruiter", key="recruiter_mail")
|
177 |
# client_mail = st.text_input("Please enter the mail of the client", key="client_mail")
|
178 |
# candidate_mail = st.text_input("Please enter the mail of the candidate", key="candidate_mail")
|
179 |
+
st.toggle("Activate to create an assessment appointment, otherwise a candidate interview is going to be created", key="assessment_toggle")
|
180 |
+
st.button("Create appointment", key="create_button", disabled=False if st.session_state["subject_input"] else True, on_click=create_button_handler)
|
181 |
|
182 |
+
if st.session_state["appointment_response"]:
|
183 |
+
st.success("The appointment was created correctly.")
|
184 |
+
st.write(os.environ.get('BASE_API')+"/meeting-consent?redirect="+st.session_state["appointment_response"]["zoom_meeting"]["start_url"].replace("https://us06web.zoom.us/s/", ""))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
openai==0.28.1
|
2 |
streamlit
|
3 |
python-dotenv
|
4 |
-
azure-cosmos
|
|
|
|
1 |
openai==0.28.1
|
2 |
streamlit
|
3 |
python-dotenv
|
4 |
+
azure-cosmos
|
5 |
+
pydantic
|