danielrosehill commited on
Commit
cdcbdc1
·
unverified ·
1 Parent(s): 7236b0c
Files changed (5) hide show
  1. .gitignore +40 -0
  2. README.md +45 -0
  3. app.py +156 -0
  4. requirements.txt +4 -0
  5. sp.md +36 -0
.gitignore ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ env/
8
+ build/
9
+ develop-eggs/
10
+ dist/
11
+ downloads/
12
+ eggs/
13
+ .eggs/
14
+ lib/
15
+ lib64/
16
+ parts/
17
+ sdist/
18
+ var/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environment
24
+ venv/
25
+ ENV/
26
+
27
+ # IDE
28
+ .idea/
29
+ .vscode/
30
+ *.swp
31
+ *.swo
32
+
33
+ # Hugging Face
34
+ .huggingface/
35
+
36
+ # OpenAI API keys
37
+ .env
38
+
39
+ # Misc
40
+ .DS_Store
README.md CHANGED
@@ -10,4 +10,49 @@ pinned: false
10
  short_description: Converts personal system prompts for general use
11
  ---
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
10
  short_description: Converts personal system prompts for general use
11
  ---
12
 
13
+ # System Prompt Depersonaliser
14
+
15
+ This application helps you convert personalized LLM system prompts into depersonalized versions that can be shared with and used by a wider audience.
16
+
17
+ ## What It Does
18
+
19
+ The System Prompt Depersonaliser:
20
+
21
+ 1. Takes a personalized system prompt as input
22
+ 2. Identifies and removes personal elements such as:
23
+ - Names
24
+ - Specific hardware or software configurations
25
+ - Location-specific references
26
+ - Unique use cases or workflows
27
+ - Personal preferences or requirements
28
+ 3. Replaces personal references with generic alternatives
29
+ 4. Maintains the core functionality and purpose of the original prompt
30
+ 5. Preserves the overall structure and flow of instructions
31
+
32
+ ## How to Use
33
+
34
+ 1. Enter your personalized system prompt in the input box
35
+ 2. Choose whether to use Hugging Face's model (free) or OpenAI (requires API key)
36
+ 3. If using OpenAI, enter your API key in the provided field
37
+ 4. Click "Depersonalize" to generate the depersonalized version
38
+ 5. Copy the result from the output box
39
+
40
+ ## Example
41
+
42
+ **Before Depersonalization:**
43
+ ```
44
+ 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.
45
+ ```
46
+
47
+ **After Depersonalization:**
48
+ ```
49
+ 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.
50
+ ```
51
+
52
+ ## Technical Details
53
+
54
+ - Built with Gradio for the user interface
55
+ - Uses either Hugging Face's free-tier models or OpenAI's API for text transformation
56
+ - Deployed as a Hugging Face Space
57
+
58
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==5.29.0
2
+ transformers
3
+ torch
4
+ openai
sp.md ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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."