Spaces:
Runtime error
Runtime error
lucidmorto
commited on
Commit
•
bd7288e
1
Parent(s):
1375ad0
feat: Update model usage and refactor text generation
Browse filesSwapped out the custom 'humanizer_model' with the generic 't5-small' model for broader compatibility. Improved text processing by refining the generation function to handle longer inputs and produce more coherent summaries. Updated UI labels and descriptions to reflect these changes, enhancing user clarity and the application’s versatility.
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer,
|
3 |
|
4 |
-
model_name = "
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
-
model =
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
outputs = model.generate(
|
11 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
|
13 |
iface = gr.Interface(
|
14 |
-
fn=
|
15 |
-
inputs=gr.Textbox(lines=5, label="
|
16 |
-
outputs=gr.Textbox(label="
|
17 |
-
title="Text
|
18 |
-
description="Enter
|
19 |
)
|
20 |
|
21 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
model_name = "t5-small"
|
5 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
7 |
|
8 |
+
def generate_text(input_text):
|
9 |
+
input_ids = tokenizer("summarize: " + input_text, return_tensors="pt", max_length=512, truncation=True).input_ids
|
10 |
+
outputs = model.generate(input_ids, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2)
|
11 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
|
13 |
iface = gr.Interface(
|
14 |
+
fn=generate_text,
|
15 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
16 |
+
outputs=gr.Textbox(label="Generated Text"),
|
17 |
+
title="Text Generator",
|
18 |
+
description="Enter text to generate a summary or continuation."
|
19 |
)
|
20 |
|
21 |
iface.launch()
|