tjido commited on
Commit
3909d7c
·
verified ·
1 Parent(s): f73ef19

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()