kevinlu1248 commited on
Commit
a65612d
1 Parent(s): 763ff9c

Final brush up

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +32 -18
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -130,30 +130,44 @@ def chunk_code(
130
  except Exception as e:
131
  return str(e)
132
 
 
 
 
 
 
 
 
 
 
 
 
133
  with gr.Blocks(css=css) as demo:
134
  gr.Markdown("## Code Chunking Demo")
135
- gr.Markdown("Start typing below and the chunked output will automatically show up. Checkout how this algorithm works at https://docs.sweep.dev/blogs/chunking-2m-files and https://docs.sweep.dev/blogs/chunking-improvements. We also have interactive notebooks at https://github.com/sweepai/sweep/blob/main/notebooks/chunking.ipynb.")
136
-
137
- default_file = "https://raw.githubusercontent.com/sweepai/sweep/b267b613d4c706eaf959fe6789f11e9a856521d1/sweepai/handlers/on_check_suite.py"
138
- default_code = requests.get(default_file).text
139
 
140
  with gr.Row():
141
- language = gr.Dropdown(["python", "javascript", "go", "ruby", "java", "php", "c", "cpp", "rust", "haskell"], label="Language", value="python")
142
  max_chars = gr.Slider(10, 3000, 1500, label="Max Characters", step=10)
143
  coalesce = gr.Slider(0, 300, 100, label="Coalesce", step=10)
 
144
  with gr.Row():
145
- inp = gr.Code(placeholder="Enter the code here", label="Code to Chunk", language=language.value, lines=60, elem_classes="code_container", value=default_code)
146
- out = gr.Code(label="Chunked Code", language=language.value, lines=60, value=chunk_code(default_code, language.value, max_chars.value, coalesce.value))
147
-
148
- def update_language(inp, language, max_chars, coalesce):
149
- return (
150
- gr.update(language=language),
151
- gr.update(language=language, value=chunk_code(inp.value, language, max_chars, coalesce))
152
- )
153
-
154
- language.change(fn=update_language, inputs=[inp, language, max_chars, coalesce], outputs=[inp, out])
155
- max_chars.change(fn=chunk_code, inputs=[inp, language, max_chars, coalesce], outputs=out)
156
- coalesce.change(fn=chunk_code, inputs=[inp, language, max_chars, coalesce], outputs=out)
157
- inp.change(fn=chunk_code, inputs=[inp, language, max_chars, coalesce], outputs=out)
 
 
 
 
 
158
 
159
  demo.launch()
 
130
  except Exception as e:
131
  return str(e)
132
 
133
+ examples_dict = {
134
+ "Python: Sweep's GiHub Actions log handler": ("https://raw.githubusercontent.com/sweepai/sweep/b267b613d4c706eaf959fe6789f11e9a856521d1/sweepai/handlers/on_check_suite.py", "python"),
135
+ "Typescript: LlamaIndex TS's BaseIndex abstract base class": ("https://raw.githubusercontent.com/run-llama/LlamaIndexTS/bfab1d407b7b390d76b3d7a1a1df0928e9f9ae11/packages/core/src/indices/BaseIndex.ts", "typescript"),
136
+ "Rust: Ruff's autofix code modification algorithm": ("https://raw.githubusercontent.com/astral-sh/ruff/main/crates/ruff/src/autofix/codemods.rs", "rust"),
137
+ "Go: Infisical's CLI's config manager": ("https://raw.githubusercontent.com/Infisical/infisical/de7bd27b4b48847c9ca7cd12d208225b06f170fe/cli/packages/util/config.go", "go")
138
+ }
139
+
140
+ default_key = "Python: GiHub Actions log handler"
141
+ default_url, default_language = examples_dict[default_key]
142
+ default_code = requests.get(default_url).text
143
+
144
  with gr.Blocks(css=css) as demo:
145
  gr.Markdown("## Code Chunking Demo")
146
+ gr.Markdown("Start typing below and the chunked output will automatically show up. Checkout how this algorithm works at https://docs.sweep.dev/blogs/chunking-2m-files and https://docs.sweep.dev/blogs/chunking-improvements or play with the notebook at https://github.com/sweepai/sweep/blob/main/notebooks/chunking.ipynb.")
 
 
 
147
 
148
  with gr.Row():
149
+ language = gr.Dropdown(['python', 'javascript', 'typescript', 'rust', 'go', 'ruby', 'r', 'html', 'css', 'shell'], label="Language", value=default_language)
150
  max_chars = gr.Slider(10, 3000, 1500, label="Max Characters", step=10)
151
  coalesce = gr.Slider(0, 300, 100, label="Coalesce", step=10)
152
+ examples = gr.Dropdown(list(examples_dict.keys()), label="Examples", value=default_key, interactive=True)
153
  with gr.Row():
154
+ input_code = gr.Code(label="Input Code", language=language.value, lines=60, elem_classes="code_container", value=default_code)
155
+ output_code = gr.Code(label="Chunked Code", language=language.value, lines=60, value=chunk_code(default_code, language.value, max_chars.value, coalesce.value))
156
+
157
+ def update_examples(examples):
158
+ url, language = examples_dict[examples]
159
+ code = requests.get(url).text
160
+ return gr.Code.update(language=language, value=code), gr.Code.update(language=language, value=chunk_code(code, language, max_chars.value, coalesce.value)), language
161
+
162
+ examples.change(fn=update_examples, inputs=examples, outputs=[input_code, output_code, language])
163
+
164
+ def update_language(language):
165
+ return gr.Code.update(language=language), gr.Code.update(language=language)
166
+
167
+ language.change(fn=update_language, inputs=language, outputs=[input_code, output_code]) \
168
+ .then(fn=chunk_code, inputs=[input_code, language, max_chars, coalesce], outputs=output_code)
169
+ max_chars.change(fn=chunk_code, inputs=[input_code, language, max_chars, coalesce], outputs=output_code)
170
+ coalesce.change(fn=chunk_code, inputs=[input_code, language, max_chars, coalesce], outputs=output_code)
171
+ input_code.change(fn=chunk_code, inputs=[input_code, language, max_chars, coalesce], outputs=output_code)
172
 
173
  demo.launch()