rishabhpr commited on
Commit
ba65c08
·
verified ·
1 Parent(s): 0ba720b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -5,32 +5,33 @@ import os
5
  # Set up OpenAI API key
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- st.title("Coding Interview Bot")
 
 
 
 
9
 
10
  # Initialize chat history
11
  if "messages" not in st.session_state:
12
- st.session_state.messages = []
13
 
14
  # Display chat messages from history on app rerun
15
- for message in st.session_state.messages:
16
  with st.chat_message(message["role"]):
17
  st.markdown(message["content"])
18
 
19
  # Function to generate response using OpenAI API
20
  def generate_response(prompt):
21
  response = openai.ChatCompletion.create(
22
- model="gpt-3.5-turbo",
23
- messages=[
24
- {"role": "system", "content": "You are a coding interview bot. Your task is to ask coding interview questions, evaluate responses, and provide feedback."},
25
- {"role": "user", "content": prompt}
26
- ],
27
  max_tokens=1000,
28
  temperature=0.7,
29
  )
30
  return response.choices[0].message['content']
31
 
32
  # React to user input
33
- if prompt := st.chat_input("What's your coding question?"):
34
  # Display user message in chat message container
35
  st.chat_message("user").markdown(prompt)
36
  # Add user message to chat history
@@ -47,6 +48,6 @@ if prompt := st.chat_input("What's your coding question?"):
47
 
48
  st.sidebar.markdown("""
49
  ## About
50
- This is a coding interview bot powered by OpenAI's GPT-3.5-turbo.
51
- Ask coding questions and get responses to help you prepare for interviews!
52
  """)
 
5
  # Set up OpenAI API key
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
+ st.title("LeetCode to Real-World Interview Question Generator")
9
+
10
+ # Load the system prompt from the file
11
+ with open("prompt.txt", "r") as file:
12
+ system_prompt = file.read()
13
 
14
  # Initialize chat history
15
  if "messages" not in st.session_state:
16
+ st.session_state.messages = [{"role": "system", "content": system_prompt}]
17
 
18
  # Display chat messages from history on app rerun
19
+ for message in st.session_state.messages[1:]: # Skip the system message
20
  with st.chat_message(message["role"]):
21
  st.markdown(message["content"])
22
 
23
  # Function to generate response using OpenAI API
24
  def generate_response(prompt):
25
  response = openai.ChatCompletion.create(
26
+ model="gpt-4",
27
+ messages=st.session_state.messages + [{"role": "user", "content": prompt}],
 
 
 
28
  max_tokens=1000,
29
  temperature=0.7,
30
  )
31
  return response.choices[0].message['content']
32
 
33
  # React to user input
34
+ if prompt := st.chat_input("Enter a LeetCode question to transform:"):
35
  # Display user message in chat message container
36
  st.chat_message("user").markdown(prompt)
37
  # Add user message to chat history
 
48
 
49
  st.sidebar.markdown("""
50
  ## About
51
+ This is a LeetCode to Real-World Interview Question Generator powered by OpenAI's GPT-4.
52
+ Enter a LeetCode question to transform it into a real-world interview scenario!
53
  """)