Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,37 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# Load a
|
| 5 |
-
generator = pipeline("text2text-generation", model="google/flan-t5-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
|
|
|
| 9 |
|
|
|
|
| 10 |
tips = []
|
| 11 |
-
if
|
| 12 |
-
tips.append("π‘
|
| 13 |
-
if not prompt
|
| 14 |
-
tips.append("π‘
|
| 15 |
-
if
|
| 16 |
-
tips.append("
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
feedback = "\n".join(tips) if tips else "β
|
| 19 |
|
| 20 |
-
return response, feedback
|
| 21 |
|
| 22 |
gr.Interface(
|
| 23 |
-
fn=
|
| 24 |
inputs="text",
|
| 25 |
outputs=["text", "text"],
|
| 26 |
-
title="
|
| 27 |
-
description="
|
| 28 |
examples=[
|
| 29 |
-
["
|
| 30 |
-
["
|
| 31 |
-
["
|
| 32 |
]
|
| 33 |
).launch()
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load a small model for faster response
|
| 5 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 6 |
|
| 7 |
+
def turtle_prompt_coach(prompt):
|
| 8 |
+
# Generate turtle code
|
| 9 |
+
response = generator(f"Write turtle graphics code to: {prompt}", max_length=200, num_return_sequences=1)[0]['generated_text']
|
| 10 |
|
| 11 |
+
# Feedback rules
|
| 12 |
tips = []
|
| 13 |
+
if "star" not in prompt.lower():
|
| 14 |
+
tips.append("π‘ Tip: Mention that you want a **star** shape.")
|
| 15 |
+
if "5" not in prompt and "five" not in prompt.lower():
|
| 16 |
+
tips.append("π‘ Tip: How many points? Try saying '5-pointed star'.")
|
| 17 |
+
if "angle" not in prompt.lower() and "degree" not in prompt.lower():
|
| 18 |
+
tips.append("π‘ Tip: Include angles or directions, like 'turn right 144 degrees'.")
|
| 19 |
+
if "turtle" not in prompt.lower():
|
| 20 |
+
tips.append("π‘ Tip: Mention 'turtle graphics' so the AI knows the style of code you want.")
|
| 21 |
|
| 22 |
+
feedback = "\n".join(tips) if tips else "β
Nice prompt! You gave clear instructions for turtle to draw a star."
|
| 23 |
|
| 24 |
+
return response.strip(), feedback
|
| 25 |
|
| 26 |
gr.Interface(
|
| 27 |
+
fn=turtle_prompt_coach,
|
| 28 |
inputs="text",
|
| 29 |
outputs=["text", "text"],
|
| 30 |
+
title="π Turtle Graphics Prompting Coach",
|
| 31 |
+
description="Describe the star you want turtle to draw. Get code + tips to improve your prompt!",
|
| 32 |
examples=[
|
| 33 |
+
["Draw a 5-pointed star using turtle graphics"],
|
| 34 |
+
["Use turtle to draw a star with angles"],
|
| 35 |
+
["Make a star using forward and right commands"],
|
| 36 |
]
|
| 37 |
).launch()
|