tjido commited on
Commit
6f70e3c
Β·
verified Β·
1 Parent(s): 1f3ca83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -1,33 +1,37 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Load a better AI model
5
- generator = pipeline("text2text-generation", model="google/flan-t5-base")
6
 
7
- def prompting_coach(prompt):
8
- response = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
 
9
 
 
10
  tips = []
11
- if len(prompt.split()) < 5:
12
- tips.append("🟑 Try making your prompt longer for better results.")
13
- if not prompt.endswith("?") and prompt.lower().startswith(("what", "how", "why")):
14
- tips.append("🟑 Try ending with a question mark (?) if you're asking something.")
15
- if any(word in prompt.lower() for word in ["cat", "dog", "story"]):
16
- tips.append("βœ… Nice! Specific topics help the AI stay focused.")
 
 
17
 
18
- feedback = "\n".join(tips) if tips else "βœ… Great prompt! Let's see what the AI thinks."
19
 
20
- return response, feedback
21
 
22
  gr.Interface(
23
- fn=prompting_coach,
24
  inputs="text",
25
  outputs=["text", "text"],
26
- title="πŸŽ“ Prompting Coach",
27
- description="Type a prompt and get an AI-generated response + tips to improve your prompt!",
28
  examples=[
29
- ["Tell me a story about a robot in space."],
30
- ["What is AI?"],
31
- ["Write a poem about pizza."]
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()