vsj0702 commited on
Commit
229e250
Β·
verified Β·
1 Parent(s): 5bb11d2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +237 -69
README.md CHANGED
@@ -1,69 +1,237 @@
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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Pro Code Playground
3
+ emoji: πŸ’»
4
+ colorFrom: indigo
5
+ colorTo: blue
6
+ sdk: streamlit
7
+ sdk_version: 1.47.0
8
+ app_file: app.py
9
+ pinned: true
10
+ ---
11
+
12
+ # πŸ’» Pro Code Playground
13
+
14
+ **Pro Code Playground** is an interactive, multi-language coding environment with a built-in AI assistant and live execution β€” all accessible directly from your browser.
15
+
16
+ Powered by Hugging Face Spaces, Streamlit, and Groq’s LLaMA 3.3–70B, this project merges code editing, language support, AI debugging, and even narration in a single clean, responsive app. No installations. No setup. Just code, ask, listen, and learn.
17
+
18
+ ---
19
+
20
+ ## πŸ”₯ Features
21
+
22
+ - 🧠 AI-powered Code Assistant via **Groq + LangChain**
23
+ - ✍️ Support for **Python, Java, C++, C, JavaScript, C#**
24
+ - πŸ“€ File upload with **auto language detection**
25
+ - πŸ“₯ Stdin simulation for programs needing user input
26
+ - πŸ”Š **Voice narration** of assistant responses (Edge TTS)
27
+ - πŸ’¬ Scrollable chatbot with memory and summarization
28
+ - πŸŒ“ **Dark/light theme toggle** with instant styling
29
+ - πŸ’Ύ One-click code download with proper extension
30
+ - πŸ§ͺ Runtime stats (execution time, memory used)
31
+
32
+ ---
33
+
34
+ ## πŸš€ Try It Live
35
+
36
+ πŸ‘‰ [Click here to run it](https://huggingface.co/spaces/vsj0702/Code_editor)
37
+ No login or install required β€” it runs right in your browser.
38
+
39
+ ---
40
+
41
+ # πŸ“˜ Usage Guide
42
+
43
+ ### πŸŒ™ 1. Toggle Light/Dark Theme
44
+
45
+ - Click the theme button (πŸŒ™ or β˜€οΈ) on the top-right to switch between dark and light modes.
46
+ - Styling is fully dynamic and applies instantly to all components including the code editor and chat.
47
+
48
+ ---
49
+
50
+ ### πŸ§‘β€πŸ’» 2. Select a Language
51
+
52
+ - Choose from: Python, Java, C, C++, JavaScript, or C#
53
+ - Language auto-switches when uploading supported files
54
+
55
+ ---
56
+
57
+ ### πŸ“ 3. Write or Upload Code
58
+
59
+ - Start writing code directly in the editor
60
+ - Or upload a file: `.py`, `.cpp`, `.c`, `.java`, `.js`, `.cs`, `.txt`
61
+ - The editor auto-switches to the detected language
62
+
63
+ ---
64
+
65
+ ### πŸ§ͺ 4. Input (stdin)
66
+
67
+ - Use the **Input (stdin)** text box for user inputs
68
+ - Inputs are passed line-by-line to your code
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!