Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a tiny, CPU-friendly model for code explanation
|
| 5 |
+
# 'codet5-small' is lightweight and handles multiple languages well
|
| 6 |
+
explainer = pipeline("summarization", model="Salesforce/codet5-small")
|
| 7 |
+
|
| 8 |
+
# Custom CSS to make it look "Zenith" style
|
| 9 |
+
custom_css = """
|
| 10 |
+
#container { max-width: 500px; margin: auto; }
|
| 11 |
+
.gradio-container { background-color: #0b0f19; color: white; }
|
| 12 |
+
footer { visibility: hidden; }
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
def explain_logic(code_input):
|
| 16 |
+
if not code_input.strip():
|
| 17 |
+
return "Please paste some code to get started!"
|
| 18 |
+
|
| 19 |
+
# We prefix the input so the model knows it's an explanation task
|
| 20 |
+
input_text = f"explain: {code_input}"
|
| 21 |
+
result = explainer(input_text, max_length=100, min_length=30, do_sample=False)
|
| 22 |
+
return result[0]['summary_text']
|
| 23 |
+
|
| 24 |
+
# Building the Interface
|
| 25 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="slate"), css=custom_css) as demo:
|
| 26 |
+
gr.Markdown("## β‘ Zenith Code Explainer")
|
| 27 |
+
gr.Markdown("Paste your logic below to get a simplified explanation. Optimized for mobile.")
|
| 28 |
+
|
| 29 |
+
with gr.Column(elem_id="container"):
|
| 30 |
+
code_box = gr.Textbox(
|
| 31 |
+
label="Input Code",
|
| 32 |
+
placeholder="e.g., print([x**2 for x in range(5)])",
|
| 33 |
+
lines=8,
|
| 34 |
+
elem_id="code-input"
|
| 35 |
+
)
|
| 36 |
+
submit_btn = gr.Button("Explain Logic", variant="primary")
|
| 37 |
+
|
| 38 |
+
output_text = gr.Textbox(
|
| 39 |
+
label="Simple Explanation",
|
| 40 |
+
interactive=False,
|
| 41 |
+
lines=5
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
submit_btn.click(fn=explain_logic, inputs=code_box, outputs=output_text)
|
| 45 |
+
|
| 46 |
+
demo.launch()
|