yxmnjxzx commited on
Commit
1ab9227
·
verified ·
1 Parent(s): f32a8f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -154
app.py CHANGED
@@ -6,6 +6,7 @@ from groq import Groq
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
 
9
 
10
  class PromptInput(BaseModel):
11
  text: str = Field(..., description="The initial prompt text")
@@ -92,9 +93,112 @@ class PromptRefiner:
92
  def apply_prompt(self, prompt: str, model: str) -> str:
93
  try:
94
  messages = [
95
- {"role": "system", "content": "You are a helpful assistant. Answer in stylized version with latex format or markdown if relevant. Separate your answer into logical sections using level 2 headers (##) for sections and bolding (**) for subsections.Incorporate a variety of lists, headers, and text to make the answer visually appealing"},
96
- {"role": "user", "content": prompt}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  response = self.client.chat.completions.create(
100
  model=model,
@@ -113,158 +217,7 @@ class PromptRefiner:
113
  class GradioInterface:
114
  def __init__(self, prompt_refiner: PromptRefiner):
115
  self.prompt_refiner = prompt_refiner
116
- custom_css = """
117
- .container {
118
- border: 2px solid #2196F3;
119
- border-radius: 10px;
120
- padding: 12px;
121
- margin: 6px;
122
- background: white;
123
- position: relative;
124
- width: 100% !important;
125
- max-width: 1200px !important;
126
- margin: 0 auto 20px auto !important;
127
- }
128
- .container::before {
129
- position: absolute;
130
- top: -10px;
131
- left: 20px;
132
- background: white;
133
- padding: 0 10px;
134
- color: #2196F3;
135
- font-weight: bold;
136
- font-size: 1.2em;
137
- }
138
- .title-container {
139
- width: fit-content !important;
140
- margin: 0 auto !important;
141
- padding: 2px 40px !important;
142
- border: 1px solid #0066cc !important;
143
- border-radius: 10px !important;
144
- background-color: rgba(0, 102, 204, 0.05) !important;
145
- }
146
- .title-container * {
147
- text-align: center;
148
- margin: 0 !important;
149
- line-height: 1.2 !important;
150
- }
151
- .title-container h1 {
152
- font-size: 28px !important;
153
- margin-bottom: 1px !important;
154
- }
155
- .title-container h3 {
156
- font-size: 18px !important;
157
- margin-bottom: 1px !important;
158
- }
159
- .title-container p {
160
- font-size: 14px !important;
161
- margin-bottom: 1px !important;
162
- }
163
- .input-container::before {
164
- content: 'PROMPT REFINEMENT';
165
- }
166
- .analysis-container::before {
167
- content: 'ANALYSIS';
168
- }
169
- .model-container::before {
170
- content: 'MODEL APPLICATION';
171
- }
172
- .examples-container::before {
173
- content: 'EXAMPLES';
174
- }
175
- /* Resizable textbox */
176
- .input-container textarea {
177
- resize: vertical !important;
178
- min-height: 100px !important;
179
- max-height: 500px !important;
180
- width: 100% !important;
181
- border: 1px solid #ddd !important;
182
- border-radius: 4px !important;
183
- padding: 8px !important;
184
- transition: all 0.3s ease !important;
185
- }
186
- .input-container textarea:focus {
187
- border-color: #2196F3 !important;
188
- box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1) !important;
189
- }
190
- /* Radio group styling */
191
- .radio-group {
192
- background-color: rgba(0, 102, 204, 0.05) !important;
193
- padding: 10px !important;
194
- border-radius: 8px !important;
195
- border: 1px solid rgba(0, 102, 204, 0.1) !important;
196
- display: flex !important;
197
- justify-content: center !important;
198
- flex-wrap: wrap !important;
199
- gap: 8px !important;
200
- width: 100% !important;
201
- }
202
- .gradio-radio {
203
- display: flex !important;
204
- justify-content: center !important;
205
- flex-wrap: wrap !important;
206
- gap: 8px !important;
207
- }
208
- .gradio-radio label {
209
- display: flex !important;
210
- align-items: center !important;
211
- padding: 6px 12px !important;
212
- border: 1px solid #ddd !important;
213
- border-radius: 4px !important;
214
- cursor: pointer !important;
215
- background: white !important;
216
- margin: 4px !important;
217
- }
218
- .gradio-radio input[type="radio"]:checked + label {
219
- background: rgba(0, 102, 204, 0.1) !important;
220
- border-color: #0066cc !important;
221
- color: #0066cc !important;
222
- font-weight: bold !important;
223
- }
224
- /* Button styling */
225
- .gradio-button {
226
- background-color: white !important;
227
- color: #2196F3 !important;
228
- border: 2px solid #2196F3 !important;
229
- border-radius: 4px !important;
230
- padding: 8px 16px !important;
231
- margin: 10px 0 !important;
232
- font-weight: bold !important;
233
- transition: all 0.3s ease !important;
234
- }
235
- .gradio-button:hover {
236
- background-color: #2196F3 !important;
237
- color: white !important;
238
- box-shadow: 0 2px 5px rgba(33, 150, 243, 0.3) !important;
239
- }
240
- /* Accordion styling */
241
- .gradio-accordion {
242
- margin: 10px 0 !important;
243
- border: none !important;
244
- }
245
- /* Container alignment */
246
- .gradio-container {
247
- display: flex !important;
248
- flex-direction: column !important;
249
- align-items: center !important;
250
- width: 100% !important;
251
- max-width: 1200px !important;
252
- margin: 0 auto !important;
253
- }
254
- /* Dropdown styling */
255
- .gradio-dropdown {
256
- width: 100% !important;
257
- max-width: 300px !important;
258
- }
259
- /* JSON container */
260
- .full-response-json {
261
- margin-top: 20px !important;
262
- padding: 10px !important;
263
- background-color: rgba(0, 102, 204, 0.05) !important;
264
- border-radius: 8px !important;
265
- }
266
- """
267
-
268
  with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as self.interface:
269
  with gr.Column(elem_classes=["container", "title-container"]):
270
  gr.Markdown("# PROMPT++")
 
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
9
+ from custom_css import custom_css
10
 
11
  class PromptInput(BaseModel):
12
  text: str = Field(..., description="The initial prompt text")
 
93
  def apply_prompt(self, prompt: str, model: str) -> str:
94
  try:
95
  messages = [
96
+ {
97
+ "role": "system",
98
+ "content": """You are a markdown formatting expert. Format your responses with proper spacing and structure following these rules:
99
+
100
+ 1. Paragraph Spacing:
101
+ - Add TWO blank lines between major sections (##)
102
+ - Add ONE blank line between subsections (###)
103
+ - Add ONE blank line between paragraphs within sections
104
+ - Add ONE blank line before and after lists
105
+ - Add ONE blank line before and after code blocks
106
+ - Add ONE blank line before and after blockquotes
107
+
108
+ 2. Section Formatting:
109
+ # Title
110
+
111
+ ## Major Section
112
+
113
+ [blank line]
114
+ Content paragraph 1
115
+ [blank line]
116
+ Content paragraph 2
117
+ [blank line]
118
+
119
+ ### Subsection
120
+ [blank line]
121
+ Content
122
+ [blank line]
123
+
124
+ 3. List Formatting:
125
+ [blank line]
126
+ - List item 1
127
+ - List item 2
128
+ - List item 3
129
+ [blank line]
130
+
131
+ 4. JSON Output Structure:
132
+ {
133
+ "section_name": "
134
+ Content paragraph 1
135
+
136
+ Content paragraph 2
137
+
138
+ - List item 1
139
+ - List item 2
140
+ "
141
+ }
142
+
143
+ Transform content while maintaining clear visual separation between elements. Each logical section should be clearly distinguished with appropriate spacing."""
144
+ },
145
+ {
146
+ "role": "user",
147
+ "content": prompt
148
+ }
149
  ]
150
+ ''' messages = [
151
+ {
152
+ "role": "system",
153
+ "content": """You are a professional markdown formatting expert. Transform any content into well-structured documentation following these precise rules:
154
+
155
+ 1. Document Structure:
156
+ - Start with # for main title
157
+ - Use ## for major sections
158
+ - Use ### for subsections
159
+ - Add > blockquote for key summaries or important notes
160
+ - Separate major sections with ---
161
+
162
+ 2. Content Types:
163
+ Technical:
164
+ - Use ```language for code blocks
165
+ - Format inline code with `backticks`
166
+ - Use $$ $$ for math equations
167
+ - Create tables for comparisons or data
168
+ - Use bullet points for features/characteristics
169
+
170
+ Narrative:
171
+ - Format dialogue with proper quotations
172
+ - Use *italics* for emphasis
173
+ - Keep paragraphs focused and concise
174
+
175
+ Instructional:
176
+ - Use numbered lists for steps
177
+ - Bold key terms with **emphasis**
178
+ - Add examples in code blocks
179
+ - Use tables for parameter explanations
180
+
181
+ 3. Visual Organization:
182
+ - Maximum 3 levels of headers
183
+ - Short paragraphs (3-5 sentences)
184
+ - Consistent spacing between sections
185
+ - Clear hierarchy in information
186
+ - Strategic use of line breaks
187
+
188
+ 4. Special Elements:
189
+ - Tables for structured comparisons
190
+ - Fenced code blocks with language specification
191
+ - Blockquotes for summaries/key points
192
+ - Lists only when necessary
193
+ - LaTeX for mathematical notation
194
+
195
+ Transform the content while maintaining clarity, professionalism, and readability. Focus on creating a logical flow that enhances understanding."""
196
+ },
197
+ {
198
+ "role": "user",
199
+ "content": prompt
200
+ }
201
+ ]'''
202
 
203
  response = self.client.chat.completions.create(
204
  model=model,
 
217
  class GradioInterface:
218
  def __init__(self, prompt_refiner: PromptRefiner):
219
  self.prompt_refiner = prompt_refiner
220
+ custom_css = custom_css
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as self.interface:
222
  with gr.Column(elem_classes=["container", "title-container"]):
223
  gr.Markdown("# PROMPT++")