Update app.py
Browse files
app.py
CHANGED
|
@@ -31,8 +31,6 @@ def init_sqlite():
|
|
| 31 |
conn.commit()
|
| 32 |
return conn
|
| 33 |
|
| 34 |
-
conn = init_sqlite()
|
| 35 |
-
|
| 36 |
# Create two expanded columns for wider side-by-side text areas
|
| 37 |
colu1, colu2 = st.columns([1, 1]) # Both columns have equal width
|
| 38 |
|
|
@@ -55,36 +53,46 @@ question_type = st.selectbox(
|
|
| 55 |
|
| 56 |
# Buttons for different functionalities
|
| 57 |
col1, col2, col3 = st.columns([0.3, 0.3, 0.3])
|
| 58 |
-
with col1:
|
| 59 |
-
if st.button("Run Code"):
|
| 60 |
-
try:
|
| 61 |
-
output = interpreter.run_code(code_input)
|
| 62 |
-
st.subheader("✨ Code Output ✨")
|
| 63 |
-
st.text_area("Execution Output", output, height=600, max_chars=None)
|
| 64 |
-
except Exception as e:
|
| 65 |
-
st.error(f"Error: {e}")
|
| 66 |
-
logger.error(f"Code execution error: {e}")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
with col3:
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# Feedback form (outside of the columns, after all content)
|
| 87 |
st.subheader("Feedback")
|
|
|
|
|
|
|
|
|
|
| 88 |
st.session_state.helpful = st.radio("Were the questions helpful?", ("Yes", "No"))
|
| 89 |
|
| 90 |
if st.button("Submit Feedback"):
|
|
@@ -113,4 +121,4 @@ st.markdown(
|
|
| 113 |
</style>
|
| 114 |
""",
|
| 115 |
unsafe_allow_html=True
|
| 116 |
-
)
|
|
|
|
| 31 |
conn.commit()
|
| 32 |
return conn
|
| 33 |
|
|
|
|
|
|
|
| 34 |
# Create two expanded columns for wider side-by-side text areas
|
| 35 |
colu1, colu2 = st.columns([1, 1]) # Both columns have equal width
|
| 36 |
|
|
|
|
| 53 |
|
| 54 |
# Buttons for different functionalities
|
| 55 |
col1, col2, col3 = st.columns([0.3, 0.3, 0.3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Using context manager for database connection
|
| 58 |
+
with init_sqlite() as conn:
|
| 59 |
+
with col1:
|
| 60 |
+
if st.button("Run Code"):
|
| 61 |
+
try:
|
| 62 |
+
output = interpreter.run_code(code_input)
|
| 63 |
+
st.subheader("✨ Code Output ✨")
|
| 64 |
+
st.text_area("Execution Output", output, height=600, max_chars=None)
|
| 65 |
+
except Exception as e:
|
| 66 |
+
st.error(f"Error executing code: {e}")
|
| 67 |
+
logger.error(f"Code execution error: {e}")
|
| 68 |
+
|
| 69 |
+
with col2:
|
| 70 |
+
if st.button("Generate Questions"):
|
| 71 |
+
logger.info(f"Generating {question_type.lower()}.")
|
| 72 |
+
try:
|
| 73 |
+
# Generate questions based on user selection
|
| 74 |
+
generated_questions = generate_questions(code_input, question_type)
|
| 75 |
+
st.subheader(f"🤖 Model-Generated {question_type}")
|
| 76 |
+
st.write(generated_questions)
|
| 77 |
+
except Exception as e:
|
| 78 |
+
st.error(f"Error: Could not generate questions: {e}")
|
| 79 |
+
logger.error(f"Question generation error: {e}")
|
| 80 |
|
| 81 |
+
with col3:
|
| 82 |
+
if st.button("Corrected Code"):
|
| 83 |
+
logger.info("User requested code correction.")
|
| 84 |
+
try:
|
| 85 |
+
corrected_code = get_correction_and_comments(code_input)
|
| 86 |
+
gemini_output.code(corrected_code, language="python")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
st.error(f"Error: Could not generate corrected code: {e}")
|
| 89 |
+
logger.error(f"Code correction error: {e}")
|
| 90 |
|
| 91 |
# Feedback form (outside of the columns, after all content)
|
| 92 |
st.subheader("Feedback")
|
| 93 |
+
if st.session_state.helpful is None:
|
| 94 |
+
st.session_state.helpful = "No" # default to No if not selected
|
| 95 |
+
|
| 96 |
st.session_state.helpful = st.radio("Were the questions helpful?", ("Yes", "No"))
|
| 97 |
|
| 98 |
if st.button("Submit Feedback"):
|
|
|
|
| 121 |
</style>
|
| 122 |
""",
|
| 123 |
unsafe_allow_html=True
|
| 124 |
+
)
|