lucidmorto commited on
Commit
bd7288e
1 Parent(s): 1375ad0

feat: Update model usage and refactor text generation

Browse files

Swapped 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.

Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,21 +1,21 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, T5ForConditionalGeneration
3
 
4
- model_name = "umutbozdag/humanizer_model"
5
  tokenizer = AutoTokenizer.from_pretrained(model_name)
6
- model = T5ForConditionalGeneration.from_pretrained(model_name)
7
 
8
- def humanize(text):
9
- inputs = tokenizer(text, return_tensors="pt", max_length=128, truncation=True)
10
- outputs = model.generate(**inputs, max_length=128)
11
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
12
 
13
  iface = gr.Interface(
14
- fn=humanize,
15
- inputs=gr.Textbox(lines=5, label="Formal Text"),
16
- outputs=gr.Textbox(label="Humanized Text"),
17
- title="Text Humanizer",
18
- description="Enter formal text to humanize it."
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()