Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
with gr.Tabs():
|
| 7 |
-
with gr.Tab(label="Enhance"):
|
| 8 |
-
create_demo_enhance()
|
| 9 |
-
gr.HTML("""<div style="margin: 0.75em 0;"><a href="https://www.buymeacoffee.com/Artgen" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a></div>
|
| 10 |
-
<div style="margin: 0.75em 0;">But what would really help me is a <strong>PRO subscription</strong> to Google Colab, Kaggle or Hugging Face. Many thanks.</div>""")
|
| 11 |
-
demo.launch()
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Load Falcon-7B-Instruct or fallback model
|
| 7 |
+
model_id = "tiiuae/falcon-7b-instruct"
|
| 8 |
+
polisher = pipeline("text-generation",
|
| 9 |
+
model=model_id,
|
| 10 |
+
torch_dtype="auto",
|
| 11 |
+
trust_remote_code=True)
|
| 12 |
+
|
| 13 |
+
def oxford_polish(sentence):
|
| 14 |
+
prompt = (
|
| 15 |
+
"You are an Oxford grammar professor. "
|
| 16 |
+
"Rewrite the following sentence in formal written English, following the Oxford University Style Guide. "
|
| 17 |
+
"Ensure tense matches time expressions (e.g. 'tomorrow' → future, 'yesterday' → past), "
|
| 18 |
+
"use British spelling, apply the Oxford comma, and correct uncountable nouns naturally.\n\n"
|
| 19 |
+
f"Sentence: {sentence}\n\nCorrected:"
|
| 20 |
+
)
|
| 21 |
+
out = polisher(prompt, max_new_tokens=80, do_sample=False)
|
| 22 |
+
return out[0]["generated_text"].split("Corrected:")[-1].strip()
|
| 23 |
|
| 24 |
+
# Gradio interface
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=oxford_polish,
|
| 27 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence to correct..."),
|
| 28 |
+
outputs=gr.Textbox(label="Oxford-style Correction"),
|
| 29 |
+
title="Oxford Grammar Polisher",
|
| 30 |
+
description="Rewrite sentences in formal written English using Oxford grammar rules. Powered by Falcon-7B-Instruct."
|
| 31 |
+
)
|
| 32 |
|
| 33 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|