Spaces:
Running
Running
eheguy commited on
Commit ·
861061c
1
Parent(s): c872ddc
Add automatic double pass for Enhanced mode
Browse files- humanizer.py +32 -23
humanizer.py
CHANGED
|
@@ -124,34 +124,43 @@ async def humanize_text(
|
|
| 124 |
|
| 125 |
client = Groq(api_key=api_key)
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
base_prompt = base_prompt.format(few_shot_examples=FEW_SHOT_EXAMPLES)
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
Tone guidance: {readability_mod}
|
| 144 |
|
| 145 |
Context: {purpose_mod}"""
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
client = Groq(api_key=api_key)
|
| 126 |
|
| 127 |
+
async def _single_pass(input_text: str, pass_mode: str) -> str:
|
| 128 |
+
base_prompt = PROMPTS.get(pass_mode, STANDARD_PROMPT)
|
| 129 |
|
| 130 |
+
if pass_mode == "enhanced":
|
| 131 |
+
base_prompt = base_prompt.format(few_shot_examples=FEW_SHOT_EXAMPLES)
|
|
|
|
| 132 |
|
| 133 |
+
readability_mod = READABILITY_MODIFIERS.get(
|
| 134 |
+
readability.lower(), READABILITY_MODIFIERS["neutral"]
|
| 135 |
+
)
|
| 136 |
+
purpose_mod = PURPOSE_MODIFIERS.get(
|
| 137 |
+
purpose.lower(), PURPOSE_MODIFIERS["professional"]
|
| 138 |
+
)
|
| 139 |
|
| 140 |
+
system_prompt = f"""{base_prompt}
|
| 141 |
|
| 142 |
Tone guidance: {readability_mod}
|
| 143 |
|
| 144 |
Context: {purpose_mod}"""
|
| 145 |
|
| 146 |
+
response = client.chat.completions.create(
|
| 147 |
+
model="llama-3.3-70b-versatile",
|
| 148 |
+
messages=[
|
| 149 |
+
{"role": "system", "content": system_prompt},
|
| 150 |
+
{"role": "user", "content": input_text}
|
| 151 |
+
],
|
| 152 |
+
temperature=0.85,
|
| 153 |
+
max_tokens=2000,
|
| 154 |
+
)
|
| 155 |
+
return response.choices[0].message.content.strip()
|
| 156 |
+
|
| 157 |
+
# Pass 1 — always run the requested mode
|
| 158 |
+
pass1_output = await _single_pass(text, mode)
|
| 159 |
+
|
| 160 |
+
# Pass 2 — only for enhanced mode, run standard to smooth the output
|
| 161 |
+
if mode == "enhanced":
|
| 162 |
+
pass2_output = await _single_pass(pass1_output, "standard")
|
| 163 |
+
return pass2_output
|
| 164 |
+
|
| 165 |
+
# Simple and standard only run once
|
| 166 |
+
return pass1_output
|