Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
# Change "summarization" to "text2text-generation"
|
| 7 |
-
explainer = pipeline("text2text-generation", model="Salesforce/codet5-small")
|
| 8 |
|
| 9 |
-
# Custom CSS to make it look "Zenith" style
|
| 10 |
custom_css = """
|
| 11 |
#container { max-width: 500px; margin: auto; }
|
| 12 |
.gradio-container { background-color: #0b0f19; color: white; }
|
|
@@ -17,11 +14,19 @@ def explain_logic(code_input):
|
|
| 17 |
if not code_input.strip():
|
| 18 |
return "Please paste some code to get started!"
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
input_text = f"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Building the Interface
|
| 26 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="slate"), css=custom_css) as demo:
|
| 27 |
gr.Markdown("## ⚡ Zenith Code Explainer")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# We use "text-generation" which is confirmed available in your logs
|
| 5 |
+
explainer = pipeline("text-generation", model="Salesforce/codet5-small")
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
custom_css = """
|
| 8 |
#container { max-width: 500px; margin: auto; }
|
| 9 |
.gradio-container { background-color: #0b0f19; color: white; }
|
|
|
|
| 14 |
if not code_input.strip():
|
| 15 |
return "Please paste some code to get started!"
|
| 16 |
|
| 17 |
+
# Prefix helps the model understand the context
|
| 18 |
+
input_text = f"Explain this code: {code_input}"
|
| 19 |
+
|
| 20 |
+
# We set max_new_tokens to control the length of the explanation
|
| 21 |
+
result = explainer(input_text, max_new_tokens=100, do_sample=False)
|
| 22 |
+
|
| 23 |
+
# text-generation returns a list with 'generated_text'
|
| 24 |
+
full_text = result[0]['generated_text']
|
| 25 |
+
|
| 26 |
+
# This removes the input prompt from the output so you only see the explanation
|
| 27 |
+
explanation = full_text.replace(input_text, "").strip()
|
| 28 |
+
return explanation if explanation else "The model couldn't generate an explanation for this snippet."
|
| 29 |
+
|
| 30 |
# Building the Interface
|
| 31 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="slate"), css=custom_css) as demo:
|
| 32 |
gr.Markdown("## ⚡ Zenith Code Explainer")
|