Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -201,24 +201,21 @@ def analyze_style_only(abstracts: str) -> Tuple[str, str, str]:
|
|
| 201 |
except Exception as e:
|
| 202 |
return f"Error: {str(e)}", "{}", ""
|
| 203 |
|
| 204 |
-
def
|
| 205 |
-
"""Rewrite using
|
| 206 |
-
if not style_profile.strip():
|
| 207 |
-
return "No saved style profile. Please click 'Analyze Style' first.", "{}"
|
| 208 |
if not original_text.strip():
|
| 209 |
return "Please provide text to rewrite.", "{}"
|
| 210 |
|
| 211 |
try:
|
| 212 |
style_prompt = f"""
|
| 213 |
-
|
| 214 |
|
| 215 |
-
|
| 216 |
-
{style_profile}
|
| 217 |
-
|
| 218 |
-
Rewrite the following text to match the STYLE PROFILE exactly, preserving all facts, numbers, and citations. Define acronyms on first mention.
|
| 219 |
|
| 220 |
Text:
|
| 221 |
{original_text}
|
|
|
|
|
|
|
| 222 |
"""
|
| 223 |
|
| 224 |
completion = client.chat.completions.create(
|
|
@@ -293,42 +290,27 @@ def create_deployment_instructions():
|
|
| 293 |
with gr.Blocks(title="StyleForge Lite", theme=gr.themes.Soft()) as app:
|
| 294 |
gr.Markdown("# 🔬 StyleForge Lite")
|
| 295 |
gr.Markdown(
|
| 296 |
-
"
|
| 297 |
)
|
| 298 |
style_profile_state = gr.State("")
|
| 299 |
|
| 300 |
with gr.Tab("Style Analysis & Rewrite"):
|
| 301 |
with gr.Row():
|
| 302 |
with gr.Column(scale=1):
|
| 303 |
-
abstracts_input = gr.Textbox(
|
| 304 |
-
label="📝 Optional: Paste 3–8 Abstracts (leave empty to use built‑in profile)",
|
| 305 |
-
placeholder="Paste 3–8 abstracts to learn YOUR style, or leave empty to use the embedded Dr. Banaganapalli style and examples.",
|
| 306 |
-
lines=10,
|
| 307 |
-
max_lines=15
|
| 308 |
-
)
|
| 309 |
-
gr.Markdown(
|
| 310 |
-
"Tip: Click 'Analyze Style' to generate a 10‑point profile. The profile is saved for this session."
|
| 311 |
-
)
|
| 312 |
-
|
| 313 |
original_text_input = gr.Textbox(
|
| 314 |
label="📄 Original Text to Rewrite",
|
| 315 |
-
placeholder="Enter the text you want to rewrite in
|
| 316 |
-
lines=
|
| 317 |
-
max_lines=
|
| 318 |
)
|
| 319 |
|
| 320 |
-
|
| 321 |
-
analyze_only_btn = gr.Button("🧪 Analyze Style", variant="secondary")
|
| 322 |
-
analyze_btn = gr.Button("🔍 Build Profile & Rewrite", variant="primary")
|
| 323 |
-
rewrite_saved_btn = gr.Button("✍️ Rewrite Using Saved Profile", variant="secondary")
|
| 324 |
|
| 325 |
with gr.Column(scale=1):
|
| 326 |
-
gr.Markdown("### 🧬 Style Profile")
|
| 327 |
-
profile_md = gr.Markdown("")
|
| 328 |
rewritten_output = gr.Textbox(
|
| 329 |
label="✨ Rewritten Text",
|
| 330 |
lines=12,
|
| 331 |
-
max_lines=
|
| 332 |
interactive=False
|
| 333 |
)
|
| 334 |
|
|
@@ -340,36 +322,21 @@ with gr.Blocks(title="StyleForge Lite", theme=gr.themes.Soft()) as app:
|
|
| 340 |
deployment_instructions = gr.Markdown(create_deployment_instructions())
|
| 341 |
|
| 342 |
# Connect the button to the function
|
| 343 |
-
|
| 344 |
-
fn=
|
| 345 |
-
inputs=[
|
| 346 |
-
outputs=[rewritten_output, metrics_output]
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
analyze_only_btn.click(
|
| 350 |
-
fn=analyze_style_only,
|
| 351 |
-
inputs=[abstracts_input],
|
| 352 |
-
outputs=[profile_md, metrics_output, style_profile_state]
|
| 353 |
-
)
|
| 354 |
-
|
| 355 |
-
rewrite_saved_btn.click(
|
| 356 |
-
fn=rewrite_with_profile,
|
| 357 |
-
inputs=[original_text_input, style_profile_state],
|
| 358 |
outputs=[rewritten_output, metrics_output]
|
| 359 |
)
|
| 360 |
|
| 361 |
# Add examples
|
| 362 |
gr.Examples(
|
| 363 |
examples=[
|
| 364 |
-
[
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
Tuberculosis persists as a major infectious disease globally. Here, we developed the first three-dimensional structural model of Mtb-MurA using homology modeling and molecular dynamics. Docking studies demonstrated that 5-sulfonoxyanthranilic acid derivatives exhibited optimal interaction with Mtb-MurA. This supports their potential for the rational design of selective enzyme inhibitors.""",
|
| 368 |
-
"Our study shows that the new drug works well. We tested it on cells and found good results. The drug might help treat cancer."
|
| 369 |
-
]
|
| 370 |
],
|
| 371 |
-
inputs=[
|
| 372 |
-
label="💡 Example"
|
| 373 |
)
|
| 374 |
|
| 375 |
if __name__ == "__main__":
|
|
|
|
| 201 |
except Exception as e:
|
| 202 |
return f"Error: {str(e)}", "{}", ""
|
| 203 |
|
| 204 |
+
def simple_rewrite(original_text: str) -> Tuple[str, str]:
|
| 205 |
+
"""Rewrite text using the built-in Dr. Banaganapalli style."""
|
|
|
|
|
|
|
| 206 |
if not original_text.strip():
|
| 207 |
return "Please provide text to rewrite.", "{}"
|
| 208 |
|
| 209 |
try:
|
| 210 |
style_prompt = f"""
|
| 211 |
+
{DEFAULT_STYLE_GUIDE}
|
| 212 |
|
| 213 |
+
Rewrite the following text to match the embedded style exactly, preserving all facts, numbers, and citations. Define acronyms on first mention.
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
Text:
|
| 216 |
{original_text}
|
| 217 |
+
|
| 218 |
+
Rewrite:
|
| 219 |
"""
|
| 220 |
|
| 221 |
completion = client.chat.completions.create(
|
|
|
|
| 290 |
with gr.Blocks(title="StyleForge Lite", theme=gr.themes.Soft()) as app:
|
| 291 |
gr.Markdown("# 🔬 StyleForge Lite")
|
| 292 |
gr.Markdown(
|
| 293 |
+
"Enter any text and get it rewritten in Dr. Banaganapalli's scientific writing style with scoring metrics."
|
| 294 |
)
|
| 295 |
style_profile_state = gr.State("")
|
| 296 |
|
| 297 |
with gr.Tab("Style Analysis & Rewrite"):
|
| 298 |
with gr.Row():
|
| 299 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
original_text_input = gr.Textbox(
|
| 301 |
label="📄 Original Text to Rewrite",
|
| 302 |
+
placeholder="Enter the text you want to rewrite in Dr. Banaganapalli's scientific style...",
|
| 303 |
+
lines=12,
|
| 304 |
+
max_lines=20
|
| 305 |
)
|
| 306 |
|
| 307 |
+
rewrite_btn = gr.Button("🔬 Analyze & Rewrite", variant="primary", size="lg")
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
| 310 |
rewritten_output = gr.Textbox(
|
| 311 |
label="✨ Rewritten Text",
|
| 312 |
lines=12,
|
| 313 |
+
max_lines=20,
|
| 314 |
interactive=False
|
| 315 |
)
|
| 316 |
|
|
|
|
| 322 |
deployment_instructions = gr.Markdown(create_deployment_instructions())
|
| 323 |
|
| 324 |
# Connect the button to the function
|
| 325 |
+
rewrite_btn.click(
|
| 326 |
+
fn=simple_rewrite,
|
| 327 |
+
inputs=[original_text_input],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
outputs=[rewritten_output, metrics_output]
|
| 329 |
)
|
| 330 |
|
| 331 |
# Add examples
|
| 332 |
gr.Examples(
|
| 333 |
examples=[
|
| 334 |
+
["Our study shows that the new drug works well. We tested it on cells and found good results. The drug might help treat cancer."],
|
| 335 |
+
["The research found that exercise is good for health. People who exercised more had better outcomes."],
|
| 336 |
+
["We analyzed the data and discovered important patterns. This could lead to new treatments."]
|
|
|
|
|
|
|
|
|
|
| 337 |
],
|
| 338 |
+
inputs=[original_text_input],
|
| 339 |
+
label="💡 Example Texts"
|
| 340 |
)
|
| 341 |
|
| 342 |
if __name__ == "__main__":
|