danielrosehill commited on
Commit
9627d5c
·
unverified ·
1 Parent(s): cdcbdc1
Files changed (3) hide show
  1. app.py +42 -138
  2. requirements.txt +2 -4
  3. sp.md +0 -36
app.py CHANGED
@@ -1,156 +1,60 @@
1
  import gradio as gr
2
- import os
3
- import re
4
- from transformers import pipeline
5
- from openai import OpenAI
6
 
7
- # Initialize the title and description
8
- title = "System Prompt Depersonaliser"
9
  description = """
10
- This app converts personalized LLM system prompts into depersonalized versions by removing personal elements
11
- while preserving the core functionality. Upload your personalized system prompt, and get a generalized version
12
- that can be shared with and used by a wider audience.
13
  """
14
 
15
- # Function to depersonalize using Hugging Face model
16
- def depersonalize_with_hf(personalized_prompt):
17
  try:
18
- # Using a text generation pipeline with a suitable model
19
- generator = pipeline('text2text-generation', model='google/flan-t5-base', max_length=1024)
20
-
21
- # Create a prompt that instructs the model what to do
22
- instruction = """
23
- Transform the following personalized system prompt into a generalized version by:
24
- 1. Removing personal elements (names, specific hardware/software, locations)
25
- 2. Replacing personal references with generic alternatives
26
- 3. Broadening specific technical requirements when appropriate
27
- 4. Maintaining the core functionality and purpose
28
- 5. Preserving the overall structure and flow
29
-
30
- Personalized prompt:
31
- """
32
-
33
- full_prompt = instruction + personalized_prompt
34
-
35
- # Generate the depersonalized version
36
- result = generator(full_prompt, max_length=1024)
37
- depersonalized = result[0]['generated_text']
38
-
39
- return depersonalized
40
- except Exception as e:
41
- return f"Error using Hugging Face model: {str(e)}\nPlease try using OpenAI instead."
42
-
43
- # Function to depersonalize using OpenAI
44
- def depersonalize_with_openai(personalized_prompt, api_key):
45
- try:
46
- client = OpenAI(api_key=api_key)
47
-
48
- response = client.chat.completions.create(
49
  model="gpt-3.5-turbo",
50
  messages=[
51
  {"role": "system", "content": """
52
- You are an AI assistant specializing in transforming personalized system prompts into generalized versions
53
- that can be shared with and used by a wider audience. Your task is to identify and remove personal elements
54
- while preserving the core functionality and purpose of the original prompt.
55
-
56
- Task Breakdown:
57
- 1. Analyze the Original Prompt
58
- - Identify personalized elements such as:
59
- * Names (e.g., Daniel Rosehill)
60
- * Specific hardware or software configurations
61
- * Location-specific references
62
- * Unique use cases or workflows
63
- * Personal preferences or requirements
64
-
65
- 2. Generalize the Content
66
- - Replace personal references with generic alternatives
67
- - Broaden specific technical requirements when appropriate
68
- - Maintain the core functionality and purpose
69
- - Preserve the overall structure and flow of instructions
70
-
71
- 3. Maintain Quality
72
- While generalizing the prompt:
73
- - Preserve clear instructions and constraints
74
- - Keep specialized knowledge and capabilities
75
- - Ensure the prompt remains coherent and effective
76
- - Retain unique value propositions of the original
77
-
78
- Provide only the depersonalized system prompt without any additional explanations or formatting.
79
- """},
80
- {"role": "user", "content": personalized_prompt}
81
  ],
82
- max_tokens=1500
83
  )
84
-
85
- return response.choices[0].message.content
86
  except Exception as e:
87
- return f"Error using OpenAI: {str(e)}"
88
 
89
- # Main function to process the input
90
- def process_prompt(personalized_prompt, use_openai, api_key=""):
91
- if not personalized_prompt:
92
- return "Please enter a personalized system prompt."
93
-
94
- if use_openai and not api_key:
95
- return "Please provide an OpenAI API key to use OpenAI for processing."
96
-
97
- if use_openai:
98
- return depersonalize_with_openai(personalized_prompt, api_key)
99
- else:
100
- return depersonalize_with_hf(personalized_prompt)
101
-
102
- # Create the Gradio interface
103
  with gr.Blocks() as demo:
104
  gr.Markdown(f"# {title}")
105
  gr.Markdown(description)
106
-
107
- with gr.Row():
108
- with gr.Column():
109
- input_text = gr.Textbox(
110
- label="Personalized System Prompt",
111
- placeholder="Enter your personalized system prompt here...",
112
- lines=10
113
- )
114
-
115
- with gr.Column():
116
- output_text = gr.Textbox(
117
- label="Depersonalized System Prompt",
118
- lines=10
119
- )
120
-
121
- with gr.Row():
122
- use_openai = gr.Checkbox(label="Use OpenAI (recommended for better results)")
123
-
124
- with gr.Row():
125
- api_key_input = gr.Textbox(
126
- label="OpenAI API Key (only needed if 'Use OpenAI' is checked)",
127
- placeholder="sk-...",
128
- type="password",
129
- visible=True
130
- )
131
-
132
- with gr.Row():
133
- submit_btn = gr.Button("Depersonalize")
134
-
135
- # Set up the click event
136
- submit_btn.click(
137
- fn=process_prompt,
138
- inputs=[input_text, use_openai, api_key_input],
139
- outputs=output_text
140
- )
141
-
142
- # Add example inputs
143
- gr.Examples(
144
- [
145
- [
146
- "Your task is to help Daniel identify the best way to backup his Open SUSE Linux desktop on his local network. On the local network Daniel has a Synology NAS. You should prioritise direct guidance for incremental backup tools."
147
- ],
148
- [
149
- "You are an AI assistant for Sarah Johnson, a graphic designer who uses Adobe Creative Suite on her MacBook Pro. Help Sarah organize her design files and provide tips for optimizing her workflow in Photoshop and Illustrator. Sarah prefers dark mode interfaces and needs to prepare files for both print and web."
150
- ]
151
- ],
152
- inputs=[input_text]
153
  )
154
 
155
- # Launch the app
156
- demo.launch()
 
1
  import gradio as gr
2
+ import openai
 
 
 
3
 
4
+ title = "System Prompt Depersonalizer"
 
5
  description = """
6
+ This app transforms personalized system prompts into generalized versions. Enter a prompt and an OpenAI API key.
 
 
7
  """
8
 
9
+ def depersonalize_with_openai(prompt, api_key):
 
10
  try:
11
+ openai.api_key = api_key
12
+ response = openai.ChatCompletion.create(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  model="gpt-3.5-turbo",
14
  messages=[
15
  {"role": "system", "content": """
16
+ You are an AI assistant specializing in transforming personalized system prompts into generalized versions that can be shared with and used by a wider audience. Your task is to identify and remove personal elements while preserving the core functionality and purpose of the original prompt.
17
+
18
+ Task Breakdown:
19
+ 1. Analyze the Original Prompt
20
+ - Identify personalized elements such as:
21
+ * Names (e.g., Daniel Rosehill)
22
+ * Specific hardware or software configurations
23
+ * Location-specific references
24
+ * Unique use cases or workflows
25
+ * Personal preferences or requirements
26
+
27
+ 2. Generalize the Content
28
+ - Replace personal references with generic alternatives
29
+ - Broaden specific technical requirements when appropriate
30
+ - Maintain the core functionality and purpose
31
+ - Preserve the overall structure and flow of instructions
32
+
33
+ Provide only the depersonalized system prompt without any additional explanations or formatting.
34
+ """},
35
+ {"role": "user", "content": prompt}
 
 
 
 
 
 
 
 
 
36
  ],
37
+ max_tokens=1200
38
  )
39
+ return response.choices[0].message["content"]
 
40
  except Exception as e:
41
+ return f"Error: {str(e)}"
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  with gr.Blocks() as demo:
44
  gr.Markdown(f"# {title}")
45
  gr.Markdown(description)
46
+
47
+ prompt_input = gr.Textbox(label="Personalized System Prompt", lines=10)
48
+ api_key_input = gr.Textbox(label="OpenAI API Key", type="password")
49
+
50
+ output_box = gr.Textbox(label="Depersonalized Prompt", lines=10)
51
+
52
+ run_btn = gr.Button("Depersonalize")
53
+
54
+ run_btn.click(
55
+ depersonalize_with_openai,
56
+ inputs=[prompt_input, api_key_input],
57
+ outputs=output_box
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  )
59
 
60
+ demo.launch()
 
requirements.txt CHANGED
@@ -1,4 +1,2 @@
1
- gradio==5.29.0
2
- transformers
3
- torch
4
- openai
 
1
+ gradio
2
+ openai
 
 
sp.md DELETED
@@ -1,36 +0,0 @@
1
- "You are an AI assistant specializing in transforming personalized system prompts into generalized versions that can be shared with and used by a wider audience. Your task is to identify and remove personal elements while preserving the core functionality and purpose of the original prompt.
2
-
3
- \## Task Breakdown
4
- 1\. Analyze the Original Prompt
5
- - Identify personalized elements such as:
6
- \* Names (e.g., Daniel Rosehill)
7
- \* Specific hardware or software configurations
8
- \* Location-specific references
9
- \* Unique use cases or workflows
10
- \* Personal preferences or requirements
11
-
12
- 2\. Generalize the Content
13
- - Replace personal references with generic alternatives
14
- - Broaden specific technical requirements when appropriate
15
- - Maintain the core functionality and purpose
16
- - Preserve the overall structure and flow of instructions
17
-
18
- 3\. Example Transformations
19
-
20
- \#### Before Depersonalization:
21
- \`Your task is to help Daniel identify the best way to backup his Open SUSE Linux desktop on his local network. On the local network Daniel has a Synology NAS. You should prioritise direct guidance for incremental backup tools.\`
22
-
23
- \#### After Depersonalization:
24
- \`Your task is to assist users in deploying optimal backup strategies over local area networks. Focus on providing direct guidance to help users select suitable backup tools.\`
25
-
26
- 4\. Maintain Quality
27
- While generalizing the prompt:
28
- - Preserve clear instructions and constraints
29
- - Keep specialized knowledge and capabilities
30
- - Ensure the prompt remains coherent and effective
31
- - Retain unique value propositions of the original
32
-
33
- \## Output Format
34
- Provide the depersonalized system prompt in Markdown format within a code fence for easy copying and implementation by the user.
35
- \`\`\`markdown
36
- Your task is to assist users in deploying optimal backup strategies over local area networks. Focus on providing direct guidance to help users select suitable backup tools."