danielrosehill commited on
Commit
3ee7577
Β·
1 Parent(s): b5a3c55
Files changed (2) hide show
  1. app.py +44 -52
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,56 +1,54 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
3
  from typing import Optional
4
 
5
  # System prompt for reformatting rough drafts into polished system prompts
6
  SYSTEM_PROMPT = """Your task is to assist the user by acting as a friendly assistant with the purpose of converting notes for AI assistants and reformatting them into polished, clear specifications for AI code generation agents and subagents. The text which the user will provide for your reformatting will be a rough draft describing the desired functionalities of the AI code generation agent which will likely fulfill the role of a sub-agent within a multi-agent framework focused on code generation or technical projects Upon receiving this rough draft your task is to reformat it into an improved and polished version defining a clear system prompt directing the agent in the second person you and ensuring that all of the user's desired functionalities are properly reflected in a better organised and clearer version of the system prompt intended to achieve the same deterministic behaviour as the user. as the user intended. Return this improved system prompt to the user in markdown within a code fence and without any other text. Assume each system prompt draft provided by the user to be intended as a new turn in the conversation - the previous agent specifications should not influence your generation of the next spec."""
7
 
8
- # Initialize Hugging Face Inference Client
9
- client = InferenceClient()
10
-
11
- def reformat_prompt(rough_draft: str) -> str:
12
  """
13
- Reformat a rough draft into a polished system prompt using Hugging Face free inference.
14
 
15
  Args:
 
16
  rough_draft: The rough draft text to be reformatted
17
 
18
  Returns:
19
  Reformatted system prompt or error message
20
  """
 
 
 
21
  if not rough_draft.strip():
22
- return "❌ Error: Please provide a rough draft to reformat."
23
 
24
  try:
25
- # Create the full prompt for the model
26
- full_prompt = f"{SYSTEM_PROMPT}\n\nUser input to reformat:\n{rough_draft}"
27
 
28
- # Use Hugging Face free inference with a capable model
29
- response = client.text_generation(
30
- prompt=full_prompt,
31
- model="microsoft/DialoGPT-medium", # Free model good for text processing
32
- max_new_tokens=1500,
 
 
33
  temperature=0.1,
34
- do_sample=True,
35
- return_full_text=False
36
  )
37
 
38
- return response
 
39
 
 
 
 
 
 
 
40
  except Exception as e:
41
- # Fallback to a different model if the first one fails
42
- try:
43
- response = client.text_generation(
44
- prompt=full_prompt,
45
- model="HuggingFaceH4/zephyr-7b-beta",
46
- max_new_tokens=1500,
47
- temperature=0.1,
48
- do_sample=True,
49
- return_full_text=False
50
- )
51
- return response
52
- except Exception as e2:
53
- return f"❌ Error: Unable to process request. Please try again later. ({str(e2)})"
54
 
55
  def create_interface():
56
  """Create and configure the Gradio interface."""
@@ -78,27 +76,34 @@ def create_interface():
78
 
79
  gr.HTML("""
80
  <div class="header">
81
- <h1>πŸ“š Code Gen Prompt Reformatter</h1>
82
- <p>Transform rough drafts into polished system prompts for AI code generation agents</p>
83
  </div>
84
  """)
85
 
86
  with gr.Row():
87
  with gr.Column():
 
 
 
 
 
 
 
88
  rough_draft_input = gr.Textbox(
89
- label="πŸ“ Rough Draft",
90
  placeholder="Enter your rough draft describing the desired functionalities of the AI code generation agent...",
91
  lines=10,
92
  max_lines=20
93
  )
94
 
95
  with gr.Row():
96
- clear_btn = gr.Button("πŸ—‘οΈ Clear", variant="secondary")
97
- submit_btn = gr.Button("✨ Reformat Prompt", variant="primary", scale=2)
98
 
99
  with gr.Column():
100
  output = gr.Textbox(
101
- label="πŸ“‹ Reformatted System Prompt",
102
  lines=15,
103
  max_lines=25,
104
  show_copy_button=True,
@@ -108,29 +113,16 @@ def create_interface():
108
  # Event handlers
109
  submit_btn.click(
110
  fn=reformat_prompt,
111
- inputs=[rough_draft_input],
112
  outputs=output,
113
  show_progress=True
114
  )
115
 
116
  clear_btn.click(
117
- fn=lambda: ("", ""),
118
- outputs=[rough_draft_input, output]
119
  )
120
 
121
- # Example section
122
- gr.HTML("""
123
- <div style="margin-top: 2rem; padding: 1rem; background-color: #f0f8ff; border-radius: 8px;">
124
- <h3>πŸ’‘ How to use:</h3>
125
- <ol>
126
- <li>Paste your rough draft describing the AI agent's desired functionalities</li>
127
- <li>Click "Reformat Prompt" to get a polished system prompt</li>
128
- <li>Copy the reformatted prompt for use in your multi-agent framework</li>
129
- </ol>
130
- <p><strong>Note:</strong> Each input is treated as a new turn - previous specifications won't influence the current generation.</p>
131
- <p><strong>Powered by:</strong> Hugging Face free inference API - no API keys required!</p>
132
- </div>
133
- """)
134
 
135
  return interface
136
 
 
1
  import gradio as gr
2
+ import openai
3
+ import os
4
  from typing import Optional
5
 
6
  # System prompt for reformatting rough drafts into polished system prompts
7
  SYSTEM_PROMPT = """Your task is to assist the user by acting as a friendly assistant with the purpose of converting notes for AI assistants and reformatting them into polished, clear specifications for AI code generation agents and subagents. The text which the user will provide for your reformatting will be a rough draft describing the desired functionalities of the AI code generation agent which will likely fulfill the role of a sub-agent within a multi-agent framework focused on code generation or technical projects Upon receiving this rough draft your task is to reformat it into an improved and polished version defining a clear system prompt directing the agent in the second person you and ensuring that all of the user's desired functionalities are properly reflected in a better organised and clearer version of the system prompt intended to achieve the same deterministic behaviour as the user. as the user intended. Return this improved system prompt to the user in markdown within a code fence and without any other text. Assume each system prompt draft provided by the user to be intended as a new turn in the conversation - the previous agent specifications should not influence your generation of the next spec."""
8
 
9
+ def reformat_prompt(api_key: str, rough_draft: str) -> str:
 
 
 
10
  """
11
+ Reformat a rough draft into a polished system prompt using OpenAI API.
12
 
13
  Args:
14
+ api_key: OpenAI API key
15
  rough_draft: The rough draft text to be reformatted
16
 
17
  Returns:
18
  Reformatted system prompt or error message
19
  """
20
+ if not api_key.strip():
21
+ return "Error: Please provide your OpenAI API key."
22
+
23
  if not rough_draft.strip():
24
+ return "Error: Please provide a rough draft to reformat."
25
 
26
  try:
27
+ # Initialize OpenAI client with the provided API key
28
+ client = openai.OpenAI(api_key=api_key)
29
 
30
+ # Make API call to reformat the prompt
31
+ response = client.chat.completions.create(
32
+ model="gpt-4o-mini",
33
+ messages=[
34
+ {"role": "system", "content": SYSTEM_PROMPT},
35
+ {"role": "user", "content": rough_draft}
36
+ ],
37
  temperature=0.1,
38
+ max_tokens=2000
 
39
  )
40
 
41
+ reformatted_text = response.choices[0].message.content
42
+ return reformatted_text
43
 
44
+ except openai.AuthenticationError:
45
+ return "Error: Invalid API key. Please check your OpenAI API key."
46
+ except openai.RateLimitError:
47
+ return "Error: Rate limit exceeded. Please try again later."
48
+ except openai.APIError as e:
49
+ return f"Error: OpenAI API error - {str(e)}"
50
  except Exception as e:
51
+ return f"Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  def create_interface():
54
  """Create and configure the Gradio interface."""
 
76
 
77
  gr.HTML("""
78
  <div class="header">
79
+ <h1>Code Gen Prompt Reformatter</h1>
80
+ <p>Text trans</p>
81
  </div>
82
  """)
83
 
84
  with gr.Row():
85
  with gr.Column():
86
+ api_key_input = gr.Textbox(
87
+ label="OpenAI API Key",
88
+ placeholder="sk-...",
89
+ type="password",
90
+ info="Your API key is not stored and only used for this session"
91
+ )
92
+
93
  rough_draft_input = gr.Textbox(
94
+ label="Rough Draft",
95
  placeholder="Enter your rough draft describing the desired functionalities of the AI code generation agent...",
96
  lines=10,
97
  max_lines=20
98
  )
99
 
100
  with gr.Row():
101
+ clear_btn = gr.Button("Clear", variant="secondary")
102
+ submit_btn = gr.Button("Reformat Prompt", variant="primary", scale=2)
103
 
104
  with gr.Column():
105
  output = gr.Textbox(
106
+ label="Reformatted System Prompt",
107
  lines=15,
108
  max_lines=25,
109
  show_copy_button=True,
 
113
  # Event handlers
114
  submit_btn.click(
115
  fn=reformat_prompt,
116
+ inputs=[api_key_input, rough_draft_input],
117
  outputs=output,
118
  show_progress=True
119
  )
120
 
121
  clear_btn.click(
122
+ fn=lambda: ("", "", ""),
123
+ outputs=[api_key_input, rough_draft_input, output]
124
  )
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  return interface
128
 
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  gradio==5.45.0
2
- huggingface_hub
 
1
  gradio==5.45.0
2
+ openai>=1.0.0