Spaces:
Paused
Paused
Update app.py
Browse files1234567891011124 unmodified lines1718192021222324252627import gradio as grfrom transformers import pipeline# Load a tiny, CPU-friendly model for code explanation# 'codet5-small' is lightweight and handles multiple languages well# Change "summarization" to "text2text-generation"explainer = pipeline("text2text-generation", model="Salesforce/codet5-small")# Custom CSS to make it look "Zenith" stylecustom_css = """#container { max-width: 500px; margin: auto; }.gradio-container { background-color: #0b0f19; color: white; }4 unmodified linesif not code_input.strip():return "Please paste some code to get started!"# We prefix the input so the model knows it's an explanation taskinput_text = f"explain: {code_input}"result = explainer(input_text, max_length=100, min_length=30, do_sample=False)return result[0]['summary_text']# Building the Interfacewith gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="slate"), css=custom_css) as demo:gr.Markdown("## ⚡ Zenith Code Explainer")1234567894 unmodified lines14151617181920212223242526272829303132import gradio as grfrom transformers import pipeline# We use "text-generation" which is confirmed available in your logsexplainer = pipeline("text-generation", model="Salesforce/codet5-small")custom_css = """#container { max-width: 500px; margin: auto; }.gradio-container { background-color: #0b0f19; color: white; }4 unmodified linesif not code_input.strip():return "Please paste some code to get started!"# Prefix helps the model understand the contextinput_text = f"Explain this code: {code_input}"# We set max_new_tokens to control the length of the explanationresult = explainer(input_text, max_new_tokens=100, do_sample=False)# text-generation returns a list with 'generated_text'full_text = result[0]['generated_text']# This removes the input prompt from the output so you only see the explanationexplanation = full_text.replace(input_text, "").strip()return explanation if explanation else "The model couldn't generate an explanation for this snippet."# Building the Interfacewith gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="slate"), css=custom_css) as demo:gr.Markdown("## ⚡ Zenith Code Explainer")
app.py+15-10