Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

components.py 5.5 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  1. import streamlit as __st
  2. from app.types import UserData
  3. def sidebar():
  4. # Omdena Logo
  5. with __st.sidebar:
  6. __st.image(image="images/omdena.png")
  7. __st.markdown(
  8. body=(
  9. "<h2><center>Hyderabad, India</center></h2>"
  10. "<center><code>Interview Preparation Chatbot</code></center>"
  11. "<hr>"
  12. ),
  13. unsafe_allow_html=True,
  14. )
  15. with __st.form(key="user_data_form", clear_on_submit=False):
  16. # Full name
  17. fullname = __st.text_input(
  18. label="Full Name",
  19. placeholder="First Last",
  20. help="Enter your full name (First & Last name)",
  21. )
  22. # Role
  23. role = __st.text_input(
  24. label="Role",
  25. placeholder="Data Scientist",
  26. help="Enter your role you are applying for (Data Scientist, Data Analyst, etc.)",
  27. )
  28. # Years of experience
  29. experience = __st.number_input(
  30. label="Years of Experience",
  31. min_value=0,
  32. max_value=20,
  33. value=0,
  34. help="Enter your years of experience",
  35. )
  36. # About
  37. about = __st.text_area(
  38. label="About",
  39. placeholder="Tell us about yourself",
  40. help="Tell us about yourself",
  41. max_chars=400,
  42. )
  43. # Resume uploader
  44. resume = __st.file_uploader(
  45. label="Upload Resume",
  46. type=["pdf", "docx"],
  47. label_visibility="visible",
  48. help="Upload your resume here",
  49. )
  50. # Submit button
  51. submit = __st.form_submit_button(label="Submit")
  52. # Validation
  53. if submit:
  54. if not fullname:
  55. __st.toast("Tell us your full name")
  56. if not role:
  57. __st.toast("Tell us the role you are applying for")
  58. if not experience:
  59. __st.toast("Tell us your years of experience")
  60. if not about:
  61. __st.toast("Tell us about yourself")
  62. if fullname and role and about:
  63. __st.toast("Your data has been submitted successfully")
  64. # Save user data
  65. __st.session_state.user_data = UserData(
  66. fullname=fullname,
  67. role=role,
  68. experience=experience,
  69. about=about,
  70. resume=resume,
  71. )
  72. __st.divider()
  73. # Footer - Copyright info
  74. __st.markdown(body="`©2023 by Omdena. All rights reserved.`", unsafe_allow_html=True)
  75. def chat() -> None:
  76. # Check if user data is available in the session state
  77. user_data = __st.session_state.user_data
  78. # Display chat messages from history on app rerun
  79. for message in __st.session_state.messages:
  80. with __st.chat_message(message["role"]):
  81. __st.markdown(message["content"])
  82. # React to user input
  83. prompt = __st.chat_input("Start typing ...", disabled=not user_data)
  84. if not user_data:
  85. # Display welcome message from assistant if user data is None
  86. welcome_message = "Hi there! Before we start, please fill out the form so I can better assist you. 📝"
  87. # Add welcome message to chat history only if it's not already present
  88. if not __st.session_state.messages or __st.session_state.messages[-1]["content"] != welcome_message:
  89. with __st.chat_message("assistant"):
  90. __st.markdown(welcome_message)
  91. __st.session_state.messages.append({"role": "assistant", "content": welcome_message})
  92. elif user_data and prompt:
  93. # Display user message in chat message container
  94. __st.chat_message("user").markdown(prompt)
  95. # Add user message to chat history
  96. __st.session_state.messages.append({"role": "user", "content": prompt})
  97. response = f"HR: {prompt}"
  98. # Display assistant response in chat message container
  99. with __st.chat_message("assistant"):
  100. __st.markdown(response)
  101. # Add assistant response to chat history
  102. __st.session_state.messages.append({"role": "assistant", "content": response})
  103. # Greet the user and start the interview questions after successful form submission
  104. if user_data and not __st.session_state.greeted:
  105. # Greet the user with their name and the role they applied for
  106. greeting_message = (
  107. f"Hi {user_data['fullname']}! Welcome to the interview for the " f"{user_data['role']} position. 🌟"
  108. )
  109. with __st.chat_message("assistant"):
  110. __st.markdown(greeting_message)
  111. # Add greeting message to chat history
  112. __st.session_state.messages.append({"role": "assistant", "content": greeting_message})
  113. # Start asking interview questions
  114. interview_start_message = (
  115. "Let's get started with the interview questions. "
  116. "I'll ask a series of questions, and you can respond when you're ready. 😊"
  117. )
  118. with __st.chat_message("assistant"):
  119. __st.markdown(interview_start_message)
  120. # Add interview start message to chat history
  121. __st.session_state.messages.append({"role": "assistant", "content": interview_start_message})
  122. # Mark the user as greeted to avoid repeating this section
  123. __st.session_state.greeted = True
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...