Spaces:
Sleeping
Sleeping
Henry Hickman commited on
Commit ·
0301a95
1
Parent(s): 6af80fd
new model
Browse files
app.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
pipe = pipeline("text-generation", model="mistralai/Mixtral", max_new_tokens=200)
|
| 6 |
|
| 7 |
def explain_code(code, level):
|
| 8 |
prompt = f"Explain what the following {level.lower()} code does:\n\n{code}\n\nExplanation:"
|
| 9 |
result = pipe(prompt)[0]["generated_text"]
|
| 10 |
-
# Strip the prompt part off to clean the output
|
| 11 |
explanation = result[len(prompt):].strip()
|
| 12 |
return explanation
|
| 13 |
|
|
@@ -19,10 +17,7 @@ iface = gr.Interface(
|
|
| 19 |
],
|
| 20 |
outputs=gr.Textbox(label="Explanation", lines=8),
|
| 21 |
title="💡 Code Explainer",
|
| 22 |
-
description=
|
| 23 |
-
"Enter code and get a natural language explanation. "
|
| 24 |
-
"Powered by a Hugging Face text-generation model."
|
| 25 |
-
),
|
| 26 |
theme="soft",
|
| 27 |
examples=[
|
| 28 |
["for i in range(5): print(i*i)", "Python"],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
pipe = pipeline("text-generation", model="gpt2", max_new_tokens=200)
|
|
|
|
| 5 |
|
| 6 |
def explain_code(code, level):
|
| 7 |
prompt = f"Explain what the following {level.lower()} code does:\n\n{code}\n\nExplanation:"
|
| 8 |
result = pipe(prompt)[0]["generated_text"]
|
|
|
|
| 9 |
explanation = result[len(prompt):].strip()
|
| 10 |
return explanation
|
| 11 |
|
|
|
|
| 17 |
],
|
| 18 |
outputs=gr.Textbox(label="Explanation", lines=8),
|
| 19 |
title="💡 Code Explainer",
|
| 20 |
+
description="Enter code and get a natural language explanation.",
|
|
|
|
|
|
|
|
|
|
| 21 |
theme="soft",
|
| 22 |
examples=[
|
| 23 |
["for i in range(5): print(i*i)", "Python"],
|