Commit
Β·
0bbea4b
1
Parent(s):
fd93b37
commit
Browse files
app.py
CHANGED
|
@@ -119,78 +119,114 @@ with gr.Blocks(css=custom_css, title="Text Transformation Model", theme=gr.theme
|
|
| 119 |
gr.HTML("""
|
| 120 |
<div style="text-align: center; margin-bottom: 30px;">
|
| 121 |
<h1 style="background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 2.5em; margin-bottom: 10px;">
|
| 122 |
-
|
| 123 |
</h1>
|
| 124 |
<p style="font-size: 1.2em; color: #666; margin-bottom: 20px;">
|
| 125 |
-
|
| 126 |
</p>
|
| 127 |
</div>
|
| 128 |
""")
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
gr.
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
elem_classes=["transform-button"]
|
| 166 |
)
|
| 167 |
|
| 168 |
-
with gr.
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
lines=10,
|
| 172 |
-
info="Transformed text will appear here",
|
| 173 |
-
interactive=False
|
| 174 |
-
)
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
)
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
# Add JavaScript for clipboard functionality and local storage
|
| 196 |
gr.HTML("""
|
|
@@ -253,18 +289,7 @@ with gr.Blocks(css=custom_css, title="Text Transformation Model", theme=gr.theme
|
|
| 253 |
</script>
|
| 254 |
""")
|
| 255 |
|
| 256 |
-
|
| 257 |
-
gr.HTML("""
|
| 258 |
-
<div style="text-align: center; margin-top: 40px; padding: 20px; border-top: 1px solid #eee; color: #666;">
|
| 259 |
-
<p>π‘ <strong>Tips:</strong></p>
|
| 260 |
-
<ul style="text-align: left; max-width: 600px; margin: 0 auto;">
|
| 261 |
-
<li>Your API key and system prompt are saved locally in your browser</li>
|
| 262 |
-
<li>Each transformation is a single API call - the input form clears automatically</li>
|
| 263 |
-
<li>Use specific system prompts for better results (e.g., "Translate to Spanish", "Summarize in 3 bullet points")</li>
|
| 264 |
-
<li>The AI will respond with only the transformed text, no additional commentary</li>
|
| 265 |
-
</ul>
|
| 266 |
-
</div>
|
| 267 |
-
""")
|
| 268 |
|
| 269 |
if __name__ == "__main__":
|
| 270 |
app.launch()
|
|
|
|
| 119 |
gr.HTML("""
|
| 120 |
<div style="text-align: center; margin-bottom: 30px;">
|
| 121 |
<h1 style="background: linear-gradient(45deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 2.5em; margin-bottom: 10px;">
|
| 122 |
+
Single-Turn Text Transformer (In, Out)
|
| 123 |
</h1>
|
| 124 |
<p style="font-size: 1.2em; color: #666; margin-bottom: 20px;">
|
| 125 |
+
A pattern for simple system prompt defined single turn text transformations.
|
| 126 |
</p>
|
| 127 |
</div>
|
| 128 |
""")
|
| 129 |
|
| 130 |
+
with gr.Tabs():
|
| 131 |
+
with gr.Tab("Transform Text"):
|
| 132 |
+
# API Key Section
|
| 133 |
+
with gr.Row():
|
| 134 |
+
with gr.Column():
|
| 135 |
+
api_key_input = gr.Textbox(
|
| 136 |
+
label="OpenAI API Key",
|
| 137 |
+
placeholder="Enter your OpenAI API key (sk-...)",
|
| 138 |
+
type="password",
|
| 139 |
+
info="Your API key is stored locally in your browser for this session."
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
with gr.Row():
|
| 143 |
+
with gr.Column():
|
| 144 |
+
system_prompt_input = gr.Textbox(
|
| 145 |
+
label="System Prompt",
|
| 146 |
+
placeholder="Enter your system prompt here (e.g., 'Translate the following text to French', 'Summarize this text in bullet points', etc.)",
|
| 147 |
+
lines=4,
|
| 148 |
+
info="Define how the AI should transform your input text. This prompt will be enhanced automatically for single-turn processing."
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Input/Output Section
|
| 152 |
+
with gr.Row():
|
| 153 |
+
with gr.Column(scale=1):
|
| 154 |
+
input_text = gr.Textbox(
|
| 155 |
+
label="Input Text",
|
| 156 |
+
placeholder="Paste or type your text here...",
|
| 157 |
+
lines=10,
|
| 158 |
+
info="Enter the text you want to transform"
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
transform_btn = gr.Button(
|
| 162 |
+
"β¨ Transform Text",
|
| 163 |
+
variant="primary",
|
| 164 |
+
size="lg",
|
| 165 |
+
elem_classes=["transform-button"]
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
with gr.Column(scale=1):
|
| 169 |
+
output_text = gr.Textbox(
|
| 170 |
+
label="Output Text",
|
| 171 |
+
lines=10,
|
| 172 |
+
info="Transformed text will appear here",
|
| 173 |
+
interactive=False
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
copy_btn = gr.Button(
|
| 177 |
+
"Copy Output",
|
| 178 |
+
variant="secondary",
|
| 179 |
+
elem_classes=["copy-button"]
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
# Event handlers
|
| 183 |
+
transform_btn.click(
|
| 184 |
+
fn=transform_text,
|
| 185 |
+
inputs=[input_text, system_prompt_input, api_key_input],
|
| 186 |
+
outputs=[output_text, input_text] # Clear input after transformation
|
| 187 |
)
|
| 188 |
|
| 189 |
+
copy_btn.click(
|
| 190 |
+
fn=copy_to_clipboard,
|
| 191 |
+
inputs=[output_text],
|
| 192 |
+
outputs=[]
|
|
|
|
| 193 |
)
|
| 194 |
|
| 195 |
+
with gr.Tab("About"):
|
| 196 |
+
gr.Markdown("""
|
| 197 |
+
## Single Turn Text Transformer
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
+
- By: [Daniel Rosehill](https://danielrosehill.com) (11-Sep-2025)
|
| 200 |
+
|
| 201 |
+
This Space provides a simple implementation of an extremely foundational but effective use for large language models (LLMs): taking a text and transforming it into something else using a sytsem prompt for guidance!
|
| 202 |
+
|
| 203 |
+
I call this Space a "model" of a "pattern" because an almost limitless variety of simple UIs can be developed around this priciple by simply alternating the underlying system prompt (which in this demo is made editable with a short concatenated element).
|
| 204 |
+
|
| 205 |
+
I call tools like these the great forgotten gems of the AI landscape: just as this AI use-case reached a high degree of stability, maturity, and cost-effectivenss it has already been lumped into the bucket of legacy tech.
|
| 206 |
+
|
| 207 |
+
## What Do You Call An Assistant That's Not An Agent?
|
| 208 |
+
|
| 209 |
+
Single turn text transformation tools like this (which lack, I argue, even a proper name!) are stateless and non-agentic and thus locked out of the glamorous agent landscape. They are single turn and non-conversational so are clearly not chatbots. At best, they might be described as "assistants" - to the extent that agents have not already usurped the term. But as assistants now connote something much more agentic, they might lack no matter name than "using AI to transform text."
|
| 210 |
+
|
| 211 |
+
Text transformers have vast application: they can be used to change the person or level of formality of text; to retsructure text from free-flowing formats into defined templates; or to clean up voice captured text, received from speech to text models, for downstream use in other systems. The model is very simple: the user prompt provides the text to be transformed and the system prompt provides the model with the desired transformation. The system prompt can also encapsulate few-shot examples to boost reliability. However, these workflows tend to execute well without even this safeguard.
|
| 212 |
+
|
| 213 |
+
## "Lived Experience"
|
| 214 |
+
|
| 215 |
+
I have implemented plenty of these.
|
| 216 |
+
|
| 217 |
+
To provide one pedestrian example: I have an agent like this whose task is to depersonalise system prompts so that I can open source them without random users getting addressed as "Daniel" or assumed to also live in Jerusalem. The system prompt asks the agent to take my system prompt and remove it of any details unique to my life - replace 'Daniel' with 'the user', etc. It's a simple in-out workflow that can (of course) be scripted and run in batches and programatically but which is just as often more useful through a simple browser UI. And it doesn't get much simpler than a form in and form out!
|
| 218 |
+
|
| 219 |
+
Other reasons why I love these tools:
|
| 220 |
+
|
| 221 |
+
- They leverage a very foundational and intended use of LLMs. This is not a frontier use or cojoling LLMs into doing something we hope might work. It was what they were designed for. If you share my conviction that tools usually are best at what they were built for, this one's a winner.
|
| 222 |
+
- They are forgiving. You don't need a model branded as having PhD level reasoning to get these to work reliably well. Hence, they are cheap. And a huge advantage of affordabilty: you can spend plenty of time working on great system prompting until you achieve the perfect desired type of text reformatting.
|
| 223 |
+
- They are great, too, for just demonstrating the utility of AI away from the hype cycle. They do something that even the most advanced RegEx patterns cant'. They work great locally, too.
|
| 224 |
+
- You just need a prompt: No tooling, no MCP integrations. Unless you're trying to transform encyclopedias in one go, they won't challenge the context window of modern models. In, out.
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
""", elem_id="about-content")
|
| 230 |
|
| 231 |
# Add JavaScript for clipboard functionality and local storage
|
| 232 |
gr.HTML("""
|
|
|
|
| 289 |
</script>
|
| 290 |
""")
|
| 291 |
|
| 292 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
if __name__ == "__main__":
|
| 295 |
app.launch()
|