Spaces:
Runtime error
Runtime error
Update src/app.py
Browse files- src/app.py +51 -27
src/app.py
CHANGED
|
@@ -19,22 +19,42 @@ from langchain.prompts import PromptTemplate
|
|
| 19 |
|
| 20 |
# --- Prompt Engineering ---
|
| 21 |
prompt_template = """""
|
| 22 |
-
You are
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
"""""
|
| 39 |
QA_CHAIN_PROMPT = PromptTemplate.from_template(prompt_template)
|
| 40 |
|
|
@@ -91,9 +111,9 @@ def qa_llm(_llm):
|
|
| 91 |
# --- Main App Logic ---
|
| 92 |
|
| 93 |
def main():
|
| 94 |
-
st.set_page_config(page_title="
|
| 95 |
-
st.markdown("<h1 style='text-align:center;color:blue;'>
|
| 96 |
-
st.markdown("### Ask me anything about
|
| 97 |
|
| 98 |
# --- Sidebar for Actions ---
|
| 99 |
with st.sidebar:
|
|
@@ -107,9 +127,7 @@ def main():
|
|
| 107 |
|
| 108 |
st.markdown("---_")
|
| 109 |
st.markdown("**Sources:**")
|
| 110 |
-
st.markdown("-
|
| 111 |
-
st.markdown("- [LinkedIn](https://www.linkedin.com/in/venkatramang2003/)")
|
| 112 |
-
st.markdown("- Resume PDF(s) in `docs/` folder")
|
| 113 |
|
| 114 |
# --- Main Chat Interface ---
|
| 115 |
if not os.path.exists(PERSIST_DIR):
|
|
@@ -125,12 +143,18 @@ def main():
|
|
| 125 |
|
| 126 |
# Pre-defined questions
|
| 127 |
example_prompts = [
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
]
|
|
|
|
| 134 |
cols = st.columns(2)
|
| 135 |
for i, prompt in enumerate(example_prompts):
|
| 136 |
if cols[i % 2].button(prompt):
|
|
|
|
| 19 |
|
| 20 |
# --- Prompt Engineering ---
|
| 21 |
prompt_template = """""
|
| 22 |
+
You are Python programmer, assisting a user in coding choosing algorithms explaining concepts as a assistant and tutor, confident, and concise.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
You said:
|
| 26 |
+
You are PyTutor, an expert Python programmer and teaching assistant.
|
| 27 |
+
Your role is to help users understand, design, and debug Python code confidently and clearly.
|
| 28 |
+
|
| 29 |
+
Guidelines:
|
| 30 |
+
|
| 31 |
+
Be concise, precise, and technically accurate.
|
| 32 |
+
|
| 33 |
+
Always explain the reasoning behind your code or solution.
|
| 34 |
+
|
| 35 |
+
When relevant, compare alternative approaches and explain why one is preferred.
|
| 36 |
+
|
| 37 |
+
Use simple language when explaining complex algorithms.
|
| 38 |
+
|
| 39 |
+
Prioritize clarity, correctness, and performance in code examples.
|
| 40 |
+
|
| 41 |
+
Provide step-by-step explanations for concepts or algorithms.
|
| 42 |
+
|
| 43 |
+
When teaching, use small, runnable Python snippets.
|
| 44 |
+
|
| 45 |
+
Avoid unnecessary verbosity or overgeneralization — keep answers focused and confident.
|
| 46 |
+
|
| 47 |
+
Always assume the user is learning Python actively and wants to understand, not just copy.
|
| 48 |
+
|
| 49 |
+
Tone:
|
| 50 |
+
|
| 51 |
+
Confident, concise, and instructive — like a skilled mentor guiding a student through real code.
|
| 52 |
+
Context:
|
| 53 |
+
{context}
|
| 54 |
+
|
| 55 |
+
Question: {question}
|
| 56 |
+
|
| 57 |
+
Interview Answer:
|
| 58 |
"""""
|
| 59 |
QA_CHAIN_PROMPT = PromptTemplate.from_template(prompt_template)
|
| 60 |
|
|
|
|
| 111 |
# --- Main App Logic ---
|
| 112 |
|
| 113 |
def main():
|
| 114 |
+
st.set_page_config(page_title="Python DSA Tutor", layout="centered")
|
| 115 |
+
st.markdown("<h1 style='text-align:center;color:blue;'> Python DSA Tutor 🤖</h1>", unsafe_allow_html=True)
|
| 116 |
+
st.markdown("### Ask me anything about Python Programming and DSA")
|
| 117 |
|
| 118 |
# --- Sidebar for Actions ---
|
| 119 |
with st.sidebar:
|
|
|
|
| 127 |
|
| 128 |
st.markdown("---_")
|
| 129 |
st.markdown("**Sources:**")
|
| 130 |
+
st.markdown("- PDF(s) in `docs/` folder")
|
|
|
|
|
|
|
| 131 |
|
| 132 |
# --- Main Chat Interface ---
|
| 133 |
if not os.path.exists(PERSIST_DIR):
|
|
|
|
| 143 |
|
| 144 |
# Pre-defined questions
|
| 145 |
example_prompts = [
|
| 146 |
+
"Explain the difference between time and space complexity with examples.",
|
| 147 |
+
"Write an optimized Python solution for the Two Sum problem and explain your approach.",
|
| 148 |
+
"Can you walk me through how to solve a problem using dynamic programming?",
|
| 149 |
+
"Show me how to implement binary search and analyze its complexity.",
|
| 150 |
+
"Compare BFS and DFS in terms of use cases and efficiency.",
|
| 151 |
+
"What are the most common sorting algorithms used in interviews?",
|
| 152 |
+
"Explain how to detect a cycle in a linked list using Floyd’s algorithm.",
|
| 153 |
+
"Give me the Python code for merging two sorted arrays efficiently.",
|
| 154 |
+
"Walk me through solving a problem with recursion and then optimizing it with memoization.",
|
| 155 |
+
"How do I explain my approach to an interviewer for a graph traversal problem?"
|
| 156 |
]
|
| 157 |
+
|
| 158 |
cols = st.columns(2)
|
| 159 |
for i, prompt in enumerate(example_prompts):
|
| 160 |
if cols[i % 2].button(prompt):
|