Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,23 @@
|
|
| 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=
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
def
|
| 14 |
prompt = (
|
| 15 |
"You are an Oxford grammar professor. "
|
| 16 |
"Rewrite the following sentence in formal written English, following the Oxford University Style Guide. "
|
|
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 5 |
|
|
|
|
| 6 |
model_id = "tiiuae/falcon-7b-instruct"
|
| 7 |
+
|
| 8 |
+
# Load tokenizer and model with trust_remote_code
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,
|
| 11 |
+
trust_remote_code=True,
|
| 12 |
+
torch_dtype="auto")
|
| 13 |
+
|
| 14 |
+
# Create pipeline (no use_cache to avoid past_key_values crash)
|
| 15 |
polisher = pipeline("text-generation",
|
| 16 |
+
model=model,
|
| 17 |
+
tokenizer=tokenizer,
|
| 18 |
+
device=-1)
|
| 19 |
|
| 20 |
+
def oxford_polish_strict(sentence: str) -> str:
|
| 21 |
prompt = (
|
| 22 |
"You are an Oxford grammar professor. "
|
| 23 |
"Rewrite the following sentence in formal written English, following the Oxford University Style Guide. "
|