Tuathe commited on
Commit
5116295
·
1 Parent(s): 0439e89

Fix: Move set_page_config to top to avoid StreamlitAPIException

Browse files
Files changed (1) hide show
  1. app/app.py +16 -6
app/app.py CHANGED
@@ -1,8 +1,11 @@
1
-
2
  import streamlit as st
3
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
  import torch
5
 
 
 
 
 
6
  @st.cache_resource
7
  def load_model():
8
  model = AutoModelForSeq2SeqLM.from_pretrained("Tuathe/codementor-flan")
@@ -13,11 +16,17 @@ model, tokenizer = load_model()
13
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
  model.to(device)
15
 
16
- st.set_page_config(page_title="CodeMentor AI", page_icon="💻", layout="centered")
17
-
18
- st.markdown("<h1 style='text-align: center;'>CodeMentor AI</h1>", unsafe_allow_html=True)
19
- st.markdown("<p style='text-align: center; font-size:18px;'>Your AI Coding Interview Assistant</p>", unsafe_allow_html=True)
20
-
 
 
 
 
 
 
21
  with st.sidebar:
22
  st.title("About CodeMentor AI")
23
  st.info(
@@ -27,6 +36,7 @@ with st.sidebar:
27
  st.markdown("---")
28
  st.markdown("Created by Chetan")
29
 
 
30
  user_input = st.text_area("Ask your coding question here:", height=150)
31
 
32
  if st.button("Get Answer"):
 
 
1
  import streamlit as st
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
  import torch
4
 
5
+ # MUST be the first Streamlit command
6
+ st.set_page_config(page_title="CodeMentor AI", page_icon="💻", layout="centered")
7
+
8
+ # Load model and tokenizer
9
  @st.cache_resource
10
  def load_model():
11
  model = AutoModelForSeq2SeqLM.from_pretrained("Tuathe/codementor-flan")
 
16
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
  model.to(device)
18
 
19
+ # Streamlit app UI
20
+ st.markdown(
21
+ "<h1 style='text-align: center;'>CodeMentor AI</h1>",
22
+ unsafe_allow_html=True
23
+ )
24
+ st.markdown(
25
+ "<p style='text-align: center; font-size:18px;'>Your AI Coding Interview Assistant</p>",
26
+ unsafe_allow_html=True
27
+ )
28
+
29
+ # Sidebar info
30
  with st.sidebar:
31
  st.title("About CodeMentor AI")
32
  st.info(
 
36
  st.markdown("---")
37
  st.markdown("Created by Chetan")
38
 
39
+ # Chat interface
40
  user_input = st.text_area("Ask your coding question here:", height=150)
41
 
42
  if st.button("Get Answer"):