Spaces:
Sleeping
Sleeping
Henry Hickman commited on
Commit ·
8fedf42
1
Parent(s): 0a8b56b
GPT-2 is back:
Browse files
app.py
CHANGED
|
@@ -9,20 +9,26 @@ def explain_code(code, level):
|
|
| 9 |
explanation = result[len(prompt):].strip()
|
| 10 |
return explanation
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
]
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
explanation = result[len(prompt):].strip()
|
| 10 |
return explanation
|
| 11 |
|
| 12 |
+
def update_language(level):
|
| 13 |
+
# Map language names to Gradio code block identifiers
|
| 14 |
+
lang_map = {
|
| 15 |
+
"Python": "python",
|
| 16 |
+
"C": "c",
|
| 17 |
+
"JavaScript": "javascript",
|
| 18 |
+
"Other": "text"
|
| 19 |
+
}
|
| 20 |
+
return gr.update(language=lang_map.get(level, "text"))
|
| 21 |
+
|
| 22 |
+
with gr.Blocks(title="💡 Code Explainer") as demo:
|
| 23 |
+
gr.Markdown("### Enter code and get a natural language explanation.")
|
| 24 |
+
|
| 25 |
+
lang = gr.Radio(["Python", "C", "JavaScript", "Other"], value="Python", label="Language")
|
| 26 |
+
code = gr.Code(language="python", label="Code", lines=12)
|
| 27 |
+
output = gr.Textbox(label="Explanation", lines=8)
|
| 28 |
+
|
| 29 |
+
lang.change(fn=update_language, inputs=lang, outputs=code)
|
| 30 |
+
btn = gr.Button("Explain Code")
|
| 31 |
+
|
| 32 |
+
btn.click(fn=explain_code, inputs=[code, lang], outputs=output)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|