danielrosehill commited on
Commit
1c4d0ed
·
unverified ·
1 Parent(s): 9627d5c
Files changed (1) hide show
  1. app.py +45 -13
app.py CHANGED
@@ -1,15 +1,17 @@
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": """
@@ -30,31 +32,61 @@ Task Breakdown:
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()
 
1
  import gradio as gr
2
  import openai
3
+ import os
4
 
5
  title = "System Prompt Depersonalizer"
6
  description = """
7
+ This app transforms personalized system prompts into generalized versions that can be shared with a wider audience.
8
  """
9
 
10
+ # Define depersonalization function using OpenAI (v1.0+ syntax)
11
+ def depersonalize_prompt(prompt, api_key):
12
  try:
13
+ client = openai.OpenAI(api_key=api_key)
14
+ response = client.chat.completions.create(
15
  model="gpt-3.5-turbo",
16
  messages=[
17
  {"role": "system", "content": """
 
32
  - Maintain the core functionality and purpose
33
  - Preserve the overall structure and flow of instructions
34
 
35
+ 3. Maintain Quality
36
+ - Preserve clear instructions and constraints
37
+ - Keep specialized knowledge and capabilities
38
+ - Ensure the prompt remains coherent and effective
39
+ - Retain unique value propositions of the original
40
+
41
+ Output Format:
42
+ Provide only the depersonalized system prompt in Markdown format inside a code block. Do not include any other commentary or explanation.
43
  """},
44
  {"role": "user", "content": prompt}
45
  ],
46
  max_tokens=1200
47
  )
48
+ return response.choices[0].message.content
49
  except Exception as e:
50
  return f"Error: {str(e)}"
51
 
52
+ # Build Gradio UI
53
  with gr.Blocks() as demo:
54
  gr.Markdown(f"# {title}")
55
  gr.Markdown(description)
56
 
57
+ api_key_input = gr.Textbox(
58
+ label="OpenAI API Key",
59
+ placeholder="sk-...",
60
+ type="password"
61
+ )
62
 
63
+ input_prompt = gr.Textbox(
64
+ label="Personalized System Prompt",
65
+ placeholder="Paste your personalized system prompt here...",
66
+ lines=10
67
+ )
68
 
69
+ output_prompt = gr.Textbox(
70
+ label="Depersonalized System Prompt",
71
+ lines=10,
72
+ interactive=True
73
+ )
74
+
75
+ with gr.Row():
76
+ run_btn = gr.Button("Depersonalize")
77
+ copy_btn = gr.Button("Copy Result")
78
 
79
  run_btn.click(
80
+ fn=depersonalize_prompt,
81
+ inputs=[input_prompt, api_key_input],
82
+ outputs=output_prompt
83
+ )
84
+
85
+ copy_btn.click(
86
+ fn=lambda x: x,
87
+ inputs=[output_prompt],
88
+ outputs=[],
89
+ js="navigator.clipboard.writeText(args[0]); alert('Copied!');"
90
  )
91
 
92
  demo.launch()