viskav commited on
Commit
dbf8209
·
verified ·
1 Parent(s): 8ac0572

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -17
app.py CHANGED
@@ -87,31 +87,47 @@ class HumanizeRequest(BaseModel):
87
  # ==================== STYLE PROMPTS ====================
88
  STYLE_PROMPTS = {
89
  "professional": """<|system|>
90
- You are a professional writing assistant. Rewrite the following text in formal, corporate business language.
91
- IMPORTANT: Output ONLY the rewritten text, nothing else.<|end|>
 
 
 
 
92
  <|user|>
93
- Text to rewrite: {text}<|end|>
94
  <|assistant|>""",
95
 
96
  "casual": """<|system|>
97
- You are a casual writing assistant. Rewrite the following text in friendly, natural, conversational English.
98
- IMPORTANT: Output ONLY the rewritten text, nothing else.<|end|>
 
 
 
 
99
  <|user|>
100
- Text to rewrite: {text}<|end|>
101
  <|assistant|>""",
102
 
103
  "academic": """<|system|>
104
- You are an academic writing assistant. Rewrite the following text in formal scholarly language.
105
- IMPORTANT: Output ONLY the rewritten text, nothing else.<|end|>
 
 
 
 
106
  <|user|>
107
- Text to rewrite: {text}<|end|>
108
  <|assistant|>""",
109
 
110
  "marketing": """<|system|>
111
- You are a marketing copywriter. Rewrite the following text into persuasive marketing language.
112
- IMPORTANT: Output ONLY the rewritten text, nothing else.<|end|>
 
 
 
 
113
  <|user|>
114
- Text to rewrite: {text}<|end|>
115
  <|assistant|>"""
116
  }
117
 
@@ -190,11 +206,13 @@ async def transform_with_model(text: str, style: str) -> str:
190
 
191
  output = llm(
192
  prompt,
193
- max_tokens=min(200, len(text) + 50),
194
- temperature=temperature,
195
- top_p=0.95,
196
- repeat_penalty=1.1,
197
- stop=["<|end|>", "\n"],
 
 
198
  echo=False,
199
  )
200
 
 
87
  # ==================== STYLE PROMPTS ====================
88
  STYLE_PROMPTS = {
89
  "professional": """<|system|>
90
+ You are a text rewriter. Your ONLY task is to rewrite the user's text in professional business language.
91
+ RULES:
92
+ 1. Output ONLY the rewritten version
93
+ 2. No explanations, no examples, no notes
94
+ 3. Keep it brief - same length as input
95
+ 4. Just rewrite, don't add content<|end|>
96
  <|user|>
97
+ Rewrite this professionally: {text}<|end|>
98
  <|assistant|>""",
99
 
100
  "casual": """<|system|>
101
+ You are a text rewriter. Your ONLY task is to rewrite the user's text in casual, conversational English.
102
+ RULES:
103
+ 1. Output ONLY the rewritten version
104
+ 2. No explanations, no examples, no notes
105
+ 3. Keep it brief - same length as input
106
+ 4. Just rewrite, don't add content<|end|>
107
  <|user|>
108
+ Rewrite this casually: {text}<|end|>
109
  <|assistant|>""",
110
 
111
  "academic": """<|system|>
112
+ You are a text rewriter. Your ONLY task is to rewrite the user's text in academic language.
113
+ RULES:
114
+ 1. Output ONLY the rewritten version
115
+ 2. No explanations, no examples, no notes
116
+ 3. Keep it brief - same length as input
117
+ 4. Just rewrite, don't add content<|end|>
118
  <|user|>
119
+ Rewrite this academically: {text}<|end|>
120
  <|assistant|>""",
121
 
122
  "marketing": """<|system|>
123
+ You are a text rewriter. Your ONLY task is to rewrite the user's text in persuasive marketing language.
124
+ RULES:
125
+ 1. Output ONLY the rewritten version
126
+ 2. No explanations, no examples, no notes
127
+ 3. Keep it brief - same length as input
128
+ 4. Just rewrite, don't add content<|end|>
129
  <|user|>
130
+ Rewrite this for marketing: {text}<|end|>
131
  <|assistant|>"""
132
  }
133
 
 
206
 
207
  output = llm(
208
  prompt,
209
+ max_tokens=150, # REDUCE further - limit output length
210
+ temperature=0.4, # Balanced creativity
211
+ top_p=0.9,
212
+ repeat_penalty=1.2, # Higher penalty for repetition
213
+ frequency_penalty=0.2, # NEW: Penalize common words
214
+ presence_penalty=0.1, # NEW: Penalize already mentioned topics
215
+ stop=["<|end|>", "\n\n", "###", "Explanation:", "For example:", "Here's how:"],
216
  echo=False,
217
  )
218