Basu03 commited on
Commit
91c0a21
·
1 Parent(s): c36fc1d

app.py chnaged

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +93 -14
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -15,32 +15,111 @@ class InterviewSession:
15
  "warnings": []
16
  }
17
 
18
- def run(self, user_input=None):
 
 
 
 
19
  if self.state["interview_status"] == 0:
 
20
  self.state = graph.invoke(self.state)
21
- elif self.state["interview_status"] == 1 and user_input:
 
 
 
 
 
 
 
22
  self.state["interview_history"].append(("user", user_input))
 
 
23
  self.state = graph.invoke(self.state)
 
 
 
 
 
 
24
 
25
- messages = []
26
- for role, text in self.state["interview_history"]:
27
- messages.append({"role": role, "content": text})
 
 
 
 
 
 
 
 
 
 
28
 
29
- if self.state["interview_status"] == 2:
30
- messages.append({"role": "assistant", "content": "✅ Interview complete."})
31
-
32
- return messages, ""
 
 
 
33
 
 
34
  session = InterviewSession()
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  demo = gr.ChatInterface(
37
- fn=session.run,
38
  title="🤖 AI-Powered Excel Interviewer (Phi-3 Mini)",
39
- chatbot=gr.Chatbot(type="messages", show_copy_button=True),
40
- textbox=gr.Textbox(placeholder="Enter your answer here...", label="Your Response"),
 
 
 
 
 
 
 
 
 
 
41
  theme="soft",
42
- submit_btn="Submit Answer"
 
 
 
 
 
 
43
  )
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  if __name__ == "__main__":
46
- demo.launch()
 
 
 
 
 
15
  "warnings": []
16
  }
17
 
18
+ def run(self, user_input, history):
19
+ """
20
+ Main chat function that handles the interview flow
21
+ """
22
+ # If this is the very first interaction, start the interview
23
  if self.state["interview_status"] == 0:
24
+ print("Starting interview...")
25
  self.state = graph.invoke(self.state)
26
+ # Convert state history to gradio format
27
+ return self._convert_history_to_gradio()
28
+
29
+ # If we have user input, process it
30
+ if user_input and user_input.strip():
31
+ print(f"Processing user input: {user_input}")
32
+
33
+ # Add user input to state history
34
  self.state["interview_history"].append(("user", user_input))
35
+
36
+ # Process the user response through the graph
37
  self.state = graph.invoke(self.state)
38
+
39
+ # Convert and return the updated history
40
+ return self._convert_history_to_gradio()
41
+
42
+ # If no input, just return current state
43
+ return self._convert_history_to_gradio()
44
 
45
+ def _convert_history_to_gradio(self):
46
+ """
47
+ Convert the internal state history to Gradio's expected format
48
+ """
49
+ gradio_history = []
50
+
51
+ for role, content in self.state["interview_history"]:
52
+ if role == "user":
53
+ gradio_history.append({"role": "user", "content": content})
54
+ elif role == "ai" or role == "assistant":
55
+ gradio_history.append({"role": "assistant", "content": content})
56
+
57
+ return gradio_history
58
 
59
+ def reset_interview(self):
60
+ """
61
+ Reset the interview session to start over
62
+ """
63
+ print("Resetting interview session...")
64
+ self.__init__()
65
+ return []
66
 
67
+ # Create a single global session instance
68
  session = InterviewSession()
69
 
70
+ def chat_fn(message, history):
71
+ """
72
+ Chat function for Gradio ChatInterface
73
+ """
74
+ return session.run(message, history)
75
+
76
+ def clear_fn():
77
+ """
78
+ Clear function to reset the interview
79
+ """
80
+ return session.reset_interview()
81
+
82
+ # Create the ChatInterface with proper configuration
83
  demo = gr.ChatInterface(
84
+ fn=chat_fn,
85
  title="🤖 AI-Powered Excel Interviewer (Phi-3 Mini)",
86
+ description="An AI-powered interview system that asks Excel-related questions and provides feedback. The system includes AI-generated response detection to ensure authentic answers.",
87
+ chatbot=gr.Chatbot(
88
+ type="messages",
89
+ show_copy_button=True,
90
+ height=600,
91
+ placeholder="Click below to start your Excel skills interview..."
92
+ ),
93
+ textbox=gr.Textbox(
94
+ placeholder="Type your answer here and press Enter...",
95
+ label="Your Response",
96
+ lines=3
97
+ ),
98
  theme="soft",
99
+ submit_btn="Submit Answer",
100
+ examples=[
101
+ "I'm ready to start the interview",
102
+ "Let's begin",
103
+ "Start the assessment"
104
+ ],
105
+ cache_examples=False
106
  )
107
 
108
+ # Add custom CSS for better styling
109
+ demo.css = """
110
+ .chat-message {
111
+ font-size: 16px;
112
+ line-height: 1.5;
113
+ }
114
+ .gradio-container {
115
+ max-width: 1200px;
116
+ margin: 0 auto;
117
+ }
118
+ """
119
+
120
  if __name__ == "__main__":
121
+ demo.launch(
122
+ share=False,
123
+ debug=True,
124
+ show_error=True
125
+ )