File size: 1,538 Bytes
020ec8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from pages.gemini import query_gemini

# Read Instructions
with open("pages/instructions/code_model_instructions.txt", "r") as f:
    model_instructions = f.read()

# Model Configuration
model_config = {
    "system_instruction": model_instructions,
    "tools": "code_execution",
}

# Intialize session state for history
if "eval_history" not in st.session_state:
    st.session_state.code_eval_history = []

# App Header
st.markdown(
    f"""
<div style="text-align: center;">
    <h4 style="margin-top: 10px;">🔍 Code Evaluator</h4>
    <h2>Ready to uncover your code’s potential?</h2>
</div>
<br>
<br>
""",
    unsafe_allow_html=True,
)
# Display chat messages from history on app rerun
for message in st.session_state.code_eval_history:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])


# Get users input
if prompt := st.chat_input("Evaluate code with SocratiQ AI..."):
    # Add user message to chat history
    st.session_state.code_eval_history.append({"role": "user", "content": prompt})
    # Display user message in chat message container
    with st.chat_message("user"):
        st.markdown(prompt)
    # Display assistant message in chat message container
    with st.chat_message("assistant"):
        response = st.write_stream(
            query_gemini(prompt, model_config, st.session_state.code_eval_history)
        )
        # Add assistant message to chat history
    st.session_state.code_eval_history.append({"role": "assistant", "content": response})