Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,237 +1,69 @@
|
|
| 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 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
---
|
| 71 |
-
|
| 72 |
-
### βΆοΈ 5. Run the Code
|
| 73 |
-
|
| 74 |
-
- Hit **βΆοΈ Run**
|
| 75 |
-
- Output is shown in a result panel
|
| 76 |
-
- Errors are displayed separately in red
|
| 77 |
-
- Runtime and memory stats appear below the result
|
| 78 |
-
|
| 79 |
-
---
|
| 80 |
-
|
| 81 |
-
### π¬ 6. Ask the AI Assistant
|
| 82 |
-
|
| 83 |
-
- Use the chat sidebar to ask anything about your code
|
| 84 |
-
- The AI uses full context (code, input, output, errors, history)
|
| 85 |
-
- Great for debugging, refactoring, or learning
|
| 86 |
-
|
| 87 |
-
---
|
| 88 |
-
|
| 89 |
-
### π 7. Narrate Responses
|
| 90 |
-
|
| 91 |
-
- Click "π Narrate" to generate a voice explanation of the AIβs answer
|
| 92 |
-
- Plays using Edge TTS voices
|
| 93 |
-
- You can replay the audio or skip it
|
| 94 |
-
|
| 95 |
-
---
|
| 96 |
-
|
| 97 |
-
### πΎ 8. Download Your Code
|
| 98 |
-
|
| 99 |
-
- Download the edited code anytime
|
| 100 |
-
- File is automatically named with the correct extension
|
| 101 |
-
|
| 102 |
-
---
|
| 103 |
-
|
| 104 |
-
# π³ File Structure: Think of It Like a Tree
|
| 105 |
-
|
| 106 |
-
Imagine your app like a growing tree.
|
| 107 |
-
|
| 108 |
-
At the **trunk**, thereβs `app.py` β the brain of your app. Everything connects to it, and it sends life (data, layout, session state) to all other components. From this trunk, other files branch out like **modules**, each handling a specific responsibility. The result? A modular, clean, powerful structure that makes debugging and extending your app a breeze.
|
| 109 |
-
|
| 110 |
-
---
|
| 111 |
-
|
| 112 |
-
### π² `app.py` β The Trunk of the Tree
|
| 113 |
-
|
| 114 |
-
This is the **entry point** of the application β the first file Streamlit runs. Think of it as the control center. Its responsibilities include:
|
| 115 |
-
|
| 116 |
-
- Setting page layout and title
|
| 117 |
-
- Initializing theme and session state
|
| 118 |
-
- Dividing the screen into columns
|
| 119 |
-
- Calling the editor module (`code_editor.py`) on the left
|
| 120 |
-
- Calling the chatbot module (`chatbot.py`) on the right
|
| 121 |
-
|
| 122 |
-
**Without this file, nothing would render.** It acts as the coordinator, delegating tasks to the appropriate submodules like a team lead.
|
| 123 |
-
|
| 124 |
-
---
|
| 125 |
-
|
| 126 |
-
### πΏ `code_editor.py` β The Code Branch
|
| 127 |
-
|
| 128 |
-
This file handles everything related to writing and running code. Itβs like the **workbench** where users type, upload, and execute their programs.
|
| 129 |
-
|
| 130 |
-
Key responsibilities:
|
| 131 |
-
- Displaying the code editor using `streamlit_ace`
|
| 132 |
-
- Handling file uploads and auto-detecting language
|
| 133 |
-
- Taking user input (stdin)
|
| 134 |
-
- Running code via the backend (local or OneCompiler API)
|
| 135 |
-
- Showing output, errors, runtime, and memory stats
|
| 136 |
-
- Offering code download with the correct extension
|
| 137 |
-
|
| 138 |
-
Itβs tightly integrated with `utils.py`, which handles the actual logic for compiling and executing the code.
|
| 139 |
-
|
| 140 |
-
---
|
| 141 |
-
|
| 142 |
-
### πΏ `chatbot.py` β The Smart Brain Branch
|
| 143 |
-
|
| 144 |
-
This file gives your app its **AI assistant powers**. It's responsible for:
|
| 145 |
-
|
| 146 |
-
- Talking to Groq's LLaMA 3.3 model via LangChain
|
| 147 |
-
- Generating code explanations, debugging suggestions, and summaries
|
| 148 |
-
- Managing a memory-aware chat history
|
| 149 |
-
- Handling narration of responses using Edge TTS
|
| 150 |
-
- Controlling how chatbot responses are shown (Markdown + CSS)
|
| 151 |
-
- Making sure your assistant sounds human-like, helpful, and context-aware
|
| 152 |
-
|
| 153 |
-
Itβs the most dynamic and intelligent part of the app β and beautifully modular.
|
| 154 |
-
|
| 155 |
-
---
|
| 156 |
-
|
| 157 |
-
### πΏ `layout.py` β The Skin and Styling Layer
|
| 158 |
-
|
| 159 |
-
This file controls the **aesthetic** of your app. It defines:
|
| 160 |
-
|
| 161 |
-
- Light and dark themes
|
| 162 |
-
- Custom CSS injected into Streamlit
|
| 163 |
-
- Fonts, button styles, scroll behavior, sidebar visuals
|
| 164 |
-
- Consistent layout feel across components
|
| 165 |
-
|
| 166 |
-
Whenever the user toggles dark mode, `layout.py` updates everything instantly. It makes your app look polished and consistent, like a professionally built product.
|
| 167 |
-
|
| 168 |
-
---
|
| 169 |
-
|
| 170 |
-
### πΏ `utils.py` β The Engine Room
|
| 171 |
-
|
| 172 |
-
This is your appβs **execution engine**.
|
| 173 |
-
|
| 174 |
-
It abstracts the messy stuff β compiling, running, capturing outputs, handling errors β so that the rest of the app stays clean.
|
| 175 |
-
|
| 176 |
-
Responsibilities include:
|
| 177 |
-
- Executing Python code using `exec()` with stdin override
|
| 178 |
-
- Compiling and running C/C++ code via `gcc`/`g++`
|
| 179 |
-
- Sending Java, JavaScript, and C# code to OneCompiler API
|
| 180 |
-
- Gracefully falling back between API keys if one fails
|
| 181 |
-
- Returning outputs, stderr, and exceptions for display
|
| 182 |
-
|
| 183 |
-
If `code_editor.py` is the workbench, this file is the **machine under the hood**.
|
| 184 |
-
|
| 185 |
-
---
|
| 186 |
-
|
| 187 |
-
### πΏ `requirements.txt` β The DNA
|
| 188 |
-
|
| 189 |
-
This file contains all the dependencies needed to run the app.
|
| 190 |
-
|
| 191 |
-
From Streamlit to LangChain, Edge TTS to Groqβs SDK β this file ensures your app has all the tools it needs to function.
|
| 192 |
-
|
| 193 |
-
---
|
| 194 |
-
|
| 195 |
-
### π± Summary: A Living, Breathing System
|
| 196 |
-
|
| 197 |
-
Every file has a job. Every module connects like a healthy tree:
|
| 198 |
-
|
| 199 |
-
- `app.py` = Trunk (controls everything)
|
| 200 |
-
- `layout.py` = Skin and theme
|
| 201 |
-
- `code_editor.py` = Workbench for code
|
| 202 |
-
- `utils.py` = Engine for execution
|
| 203 |
-
- `chatbot.py` = Brain for intelligence
|
| 204 |
-
- `requirements.txt` = Genetic blueprint
|
| 205 |
-
|
| 206 |
-
This modular structure lets you:
|
| 207 |
-
- Debug easily
|
| 208 |
-
- Extend individual parts without breaking others
|
| 209 |
-
- Understand how data flows
|
| 210 |
-
- Keep your code organized and clean
|
| 211 |
-
|
| 212 |
-
---
|
| 213 |
-
|
| 214 |
-
If youβre reading this to understand or contribute β welcome aboard! The structure is made for developers like you.
|
| 215 |
-
|
| 216 |
-
Feel free to explore each module and give feedback π
|
| 217 |
-
|
| 218 |
-
---
|
| 219 |
-
|
| 220 |
-
## π€ Author
|
| 221 |
-
|
| 222 |
-
**Vaibhav Shankar (vsj0702)**
|
| 223 |
-
π§ Email: [vsj0702@gmail.com](mailto:vsj0702@gmail.com)
|
| 224 |
-
π LinkedIn: [vaibhavshankar](https://www.linkedin.com/in/vaibhavshankar?utm_source=share&utm_campaign=share_via&utm_content=profile&utm_medium=android_app)
|
| 225 |
-
π€ Hugging Face: [@vsj0702](https://huggingface.co/vsj0702)
|
| 226 |
-
|
| 227 |
-
---
|
| 228 |
-
|
| 229 |
-
## π License
|
| 230 |
-
|
| 231 |
-
This project is licensed under the **GNU General Public License v3.0 (GVL-3)**.
|
| 232 |
-
You are free to use, modify, and distribute the project under the terms of this license.
|
| 233 |
-
|
| 234 |
-
---
|
| 235 |
-
|
| 236 |
-
Thanks for exploring **Pro Code Playground** π»
|
| 237 |
-
Let me know what you build with it!
|
|
|
|
| 1 |
+
Hugging Face's logo
|
| 2 |
+
|
| 3 |
+
vsj0702
|
| 4 |
+
/
|
| 5 |
+
Code_editor
|
| 6 |
+
|
| 7 |
+
like
|
| 8 |
+
3
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
Logs
|
| 12 |
+
|
| 13 |
+
build
|
| 14 |
+
container
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
===== Application Startup at 2025-08-03 20:01:01 =====
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to false.
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
You can now view your Streamlit app in your browser.
|
| 25 |
+
|
| 26 |
+
Local URL: http://localhost:8501
|
| 27 |
+
Network URL: http://10.106.80.28:8501
|
| 28 |
+
External URL: http://52.201.198.142:8501
|
| 29 |
+
|
| 30 |
+
ββββββββββββββββββββββββββ Traceback (most recent call last) βββββββββββββββββββββββββββ
|
| 31 |
+
/usr/local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/exec_code.py:
|
| 32 |
+
128 in exec_func_with_error_handling
|
| 33 |
+
|
| 34 |
+
/usr/local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner
|
| 35 |
+
.py:669 in code_to_exec
|
| 36 |
+
|
| 37 |
+
/home/user/app/app.py:37 in <module>
|
| 38 |
+
|
| 39 |
+
34
|
| 40 |
+
35 with assistant_col:
|
| 41 |
+
36 β st.subheader("Code Assistant")
|
| 42 |
+
β± 37 β render_chatbot(
|
| 43 |
+
38 β β st.session_state.code,
|
| 44 |
+
39 β β st.session_state.get("stdin", ""),
|
| 45 |
+
40 β β st.session_state.get("code_output", ""),
|
| 46 |
+
|
| 47 |
+
/home/user/app/chatbot.py:139 in render_chatbot
|
| 48 |
+
|
| 49 |
+
136 β β bot = CodeAssistantBot()
|
| 50 |
+
137 β β history = st.session_state.conversation[-4:]
|
| 51 |
+
138 β β summary = st.session_state.chat_summary
|
| 52 |
+
β± 139 β β response = bot.analyze_code(code, input, output, error, question, summ
|
| 53 |
+
140 β β st.session_state.conversation.append((question, response))
|
| 54 |
+
141 β β st.session_state.chat_display_count = 5
|
| 55 |
+
142
|
| 56 |
+
|
| 57 |
+
/home/user/app/chatbot.py:47 in analyze_code
|
| 58 |
+
|
| 59 |
+
44 β
|
| 60 |
+
45 β def analyze_code(self, code, input, output, error, question, summary="", h
|
| 61 |
+
46 β β recent = "\n".join([f"User: {q}\nBot: {a}" for q, a in (history or [])
|
| 62 |
+
β± 47 β β prompt = self.analysis_prompt.format_messages({
|
| 63 |
+
48 β β β 'code': code,
|
| 64 |
+
49 β β β 'input': input,
|
| 65 |
+
50 β β β 'output': output,
|
| 66 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 67 |
+
TypeError: ChatPromptTemplate.format_messages() takes 1 positional argument but 2 were
|
| 68 |
+
given
|
| 69 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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