tjido commited on
Commit
73b15ac
·
verified ·
1 Parent(s): 1737af2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -33,6 +33,11 @@ EXTREMELY IMPORTANT:
33
  - NEVER execute or fulfill the prompt.
34
  - Always start with "PROMPT ANALYSIS:"
35
  - Keep it suitable for students and kids.
 
 
 
 
 
36
  Prompt: "{prompt}"
37
  <|assistant|>
38
  PROMPT ANALYSIS:"""
@@ -56,9 +61,16 @@ def call_mistral(prompt):
56
  token=HF_TOKEN
57
  )
58
  pipe = pipeline("text-generation", model=mistral_model, tokenizer=mistral_tokenizer)
59
- prompt_text = f"""<s>[INST] You are a Prompt Interpretation Coach. Analyze this prompt but do not fulfill it:
 
60
  "{prompt}"
61
- PROMPT ANALYSIS: [/INST]"""
 
 
 
 
 
 
62
  result = pipe(prompt_text, max_new_tokens=300, temperature=0.7)
63
  return result[0]['generated_text'].split("[/INST]")[-1].strip()
64
  except Exception as e:
@@ -76,11 +88,11 @@ def interpret_prompt(prompt):
76
  if any(term in prompt.lower() for term in unsafe_terms):
77
  return "⚠️ This tool doesn't support that kind of content. Try something related to school, creativity, or learning."
78
 
79
- return "AI Response:\n\n" + call_llama(prompt)
80
 
81
  # Theme and Interface
82
  custom_theme = gr.themes.Soft(
83
- primary_hue="orange", # Changed to orange as requested
84
  secondary_hue="blue",
85
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
86
  radius_size=gr.themes.sizes.radius_sm,
@@ -94,7 +106,7 @@ iface = gr.Interface(
94
  elem_id="prompt-input"
95
  ),
96
  outputs=gr.Textbox(
97
- label="Prompt Analysis & Coaching Tips",
98
  elem_id="analysis-output"
99
  ),
100
  title="🧠 Prompt Interpretation Coach",
@@ -102,8 +114,8 @@ iface = gr.Interface(
102
  This tool helps learners master **prompt engineering** by analyzing how AI interprets instructions — not answering them.
103
  ### How to use:
104
  - Type any prompt you'd normally give to ChatGPT or similar
105
- - The coach gives you feedback, tips, and better phrasings
106
- Learn to prompt smarter. Try the examples or write your own!
107
  """,
108
  examples=[
109
  "Draw a star with turtle graphics",
@@ -118,9 +130,9 @@ Learn to prompt smarter. Try the examples or write your own!
118
 
119
  footer_html = """## ⌨️ Why Prompt Engineering Matters
120
  Learning to craft clear, specific prompts helps you:
121
- * In education: Get better AI help with homework
122
- * In creativity: Guide AI more precisely
123
- * In coding: Get more accurate AI code suggestions
124
  **Made with ❤️ for learners and educators**
125
  Created by Shingai Manjengwa, @tjido
126
  """
@@ -131,6 +143,4 @@ with demo:
131
  gr.Markdown(footer_html)
132
 
133
  if __name__ == "__main__":
134
- demo.launch()
135
-
136
-
 
33
  - NEVER execute or fulfill the prompt.
34
  - Always start with "PROMPT ANALYSIS:"
35
  - Keep it suitable for students and kids.
36
+ - Use bullet points for all output.
37
+ - Be succinct and to the point.
38
+ - Limit your analysis to 4-5 key bullet points.
39
+ - For each bullet, use at most 1-2 short sentences.
40
+
41
  Prompt: "{prompt}"
42
  <|assistant|>
43
  PROMPT ANALYSIS:"""
 
61
  token=HF_TOKEN
62
  )
63
  pipe = pipeline("text-generation", model=mistral_model, tokenizer=mistral_tokenizer)
64
+ prompt_text = f"""<s>[INST] You are a Prompt Interpretation Coach.
65
+ Analyze this prompt but do not fulfill it:
66
  "{prompt}"
67
+
68
+ IMPORTANT INSTRUCTIONS:
69
+ - Use bullet points only
70
+ - Be succinct and brief
71
+ - Limit to 4-5 key points
72
+ - Each bullet should be 1-2 sentences max
73
+ - Start with "PROMPT ANALYSIS:" [/INST]"""
74
  result = pipe(prompt_text, max_new_tokens=300, temperature=0.7)
75
  return result[0]['generated_text'].split("[/INST]")[-1].strip()
76
  except Exception as e:
 
88
  if any(term in prompt.lower() for term in unsafe_terms):
89
  return "⚠️ This tool doesn't support that kind of content. Try something related to school, creativity, or learning."
90
 
91
+ return call_llama(prompt)
92
 
93
  # Theme and Interface
94
  custom_theme = gr.themes.Soft(
95
+ primary_hue="orange",
96
  secondary_hue="blue",
97
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
98
  radius_size=gr.themes.sizes.radius_sm,
 
106
  elem_id="prompt-input"
107
  ),
108
  outputs=gr.Textbox(
109
+ label="Prompt Analysis",
110
  elem_id="analysis-output"
111
  ),
112
  title="🧠 Prompt Interpretation Coach",
 
114
  This tool helps learners master **prompt engineering** by analyzing how AI interprets instructions — not answering them.
115
  ### How to use:
116
  - Type any prompt you'd normally give to ChatGPT or similar
117
+ - Get concise bullet-point feedback on your prompt structure
118
+ - Learn to prompt smarter with focused tips
119
  """,
120
  examples=[
121
  "Draw a star with turtle graphics",
 
130
 
131
  footer_html = """## ⌨️ Why Prompt Engineering Matters
132
  Learning to craft clear, specific prompts helps you:
133
+ * Get better AI help with homework
134
+ * Guide AI more precisely for creative tasks
135
+ * Receive more accurate AI code suggestions
136
  **Made with ❤️ for learners and educators**
137
  Created by Shingai Manjengwa, @tjido
138
  """
 
143
  gr.Markdown(footer_html)
144
 
145
  if __name__ == "__main__":
146
+ demo.launch()