Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -154,4 +154,62 @@ if page == "Semantic Search":
|
|
| 154 |
with st.spinner("Running Semantic Search..."):
|
| 155 |
answer = call_groq_api(f"{question}\n\nCode:\n{code_input}")
|
| 156 |
st.success("Answer:")
|
| 157 |
-
st.write(answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
with st.spinner("Running Semantic Search..."):
|
| 155 |
answer = call_groq_api(f"{question}\n\nCode:\n{code_input}")
|
| 156 |
st.success("Answer:")
|
| 157 |
+
st.write(answer)
|
| 158 |
+
|
| 159 |
+
elif page == "AI Workflow":
|
| 160 |
+
st.header("Full AI Workflow")
|
| 161 |
+
code_input = st.text_area("Paste your code here", height=200)
|
| 162 |
+
uploaded_file = st.file_uploader("Or upload a code file", type=["py", "js", "ts", "java", "cpp", "cs"])
|
| 163 |
+
if uploaded_file:
|
| 164 |
+
code_input = uploaded_file.read().decode("utf-8")
|
| 165 |
+
st.text_area("File content", code_input, height=200, key="file_content")
|
| 166 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 167 |
+
with col1:
|
| 168 |
+
programming_language = st.selectbox("Programming Language", PROGRAMMING_LANGUAGES)
|
| 169 |
+
with col2:
|
| 170 |
+
skill_level = st.selectbox("Skill Level", SKILL_LEVELS)
|
| 171 |
+
with col3:
|
| 172 |
+
user_role = st.selectbox("Your Role", USER_ROLES)
|
| 173 |
+
with col4:
|
| 174 |
+
explanation_language = st.selectbox("Explanation Language", EXPLANATION_LANGUAGES)
|
| 175 |
+
if code_input:
|
| 176 |
+
st.caption(f"Complexity: {calculate_code_complexity(code_input)}")
|
| 177 |
+
if st.button("Run Workflow", type="primary"):
|
| 178 |
+
if not code_input.strip():
|
| 179 |
+
st.error("Please paste or upload your code.")
|
| 180 |
+
elif not code_matches_language(code_input, programming_language):
|
| 181 |
+
st.error(f"Language mismatch. Please check your code and language selection.")
|
| 182 |
+
else:
|
| 183 |
+
with st.spinner("Running AI Workflow..."):
|
| 184 |
+
steps = [
|
| 185 |
+
("Explain", call_groq_api(f"Explain this {programming_language} code for a {skill_level} {user_role} in {explanation_language}:\n{code_input}")),
|
| 186 |
+
("Refactor", call_blackbox_agent([
|
| 187 |
+
{"role": "system", "content": "You are a helpful coding assistant."},
|
| 188 |
+
{"role": "user", "content": f"Refactor this {programming_language} code: {code_input}"}
|
| 189 |
+
])),
|
| 190 |
+
("Review", call_groq_api(f"Review this {programming_language} code for errors and improvements: {code_input}")),
|
| 191 |
+
("ErrorDetection", call_groq_api(f"Find bugs in this {programming_language} code: {code_input}")),
|
| 192 |
+
("TestGeneration", call_groq_api(f"Generate tests for this {programming_language} code: {code_input}")),
|
| 193 |
+
]
|
| 194 |
+
timeline = []
|
| 195 |
+
for step, output in steps:
|
| 196 |
+
timeline.append({"step": step, "output": output})
|
| 197 |
+
st.success("Workflow complete!")
|
| 198 |
+
for t in timeline:
|
| 199 |
+
st.subheader(t["step"])
|
| 200 |
+
st.write(t["output"])
|
| 201 |
+
st.subheader("Code Diff (Original vs Refactored)")
|
| 202 |
+
refactored_code = steps[1][1]
|
| 203 |
+
st.code(get_inline_diff(code_input, refactored_code), language=programming_language.lower())
|
| 204 |
+
report = f"AI Workflow Report\nGenerated on: {datetime.datetime.now()}\nLanguage: {programming_language}\nSkill Level: {skill_level}\nRole: {user_role}\n\n"
|
| 205 |
+
for t in timeline:
|
| 206 |
+
report += f"## {t['step']}\n{t['output']}\n\n---\n\n"
|
| 207 |
+
st.download_button("Download Report", report, file_name="ai_workflow_report.txt")
|
| 208 |
+
|
| 209 |
+
if page == "Home":
|
| 210 |
+
st.header("Welcome to the AI Assistant!")
|
| 211 |
+
st.markdown("""
|
| 212 |
+
- **Full AI Workflow:** Complete code analysis pipeline with explanation, refactoring, review, and testing (powered by Groq/Blackbox)
|
| 213 |
+
- **Semantic Search:** Ask natural language questions about your code and get intelligent answers
|
| 214 |
+
""")
|
| 215 |
+
st.info("Select a feature from the sidebar to get started.")
|