File size: 1,631 Bytes
1375ad0
bd7288e
0f051eb
1375ad0
0f051eb
 
 
 
 
 
 
 
 
 
1375ad0
bd7288e
3f7af4c
 
 
 
0f051eb
3f7af4c
0f051eb
3f7af4c
 
0f051eb
3f7af4c
0f051eb
 
 
 
3f7af4c
0f051eb
 
3f7af4c
 
 
 
 
1375ad0
 
bd7288e
 
 
0f051eb
 
1375ad0
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from huggingface_hub import HfApi

# Get the latest model from your space
api = HfApi()
space_name = "umut-bozdag/humanizer_model"  # Replace with your actual space name
model_files = api.list_repo_files(space_name)
model_file = next(file for file in model_files if file.endswith('.bin'))
model_revision = api.get_repo_info(space_name).sha

# Load the model and tokenizer from the space
tokenizer = AutoTokenizer.from_pretrained(space_name, revision=model_revision)
model = AutoModelForSeq2SeqLM.from_pretrained(space_name, revision=model_revision)

def generate_text(input_text):
    # Preprocess input text
    input_text = input_text.strip()
    
    # Prepare input for the model
    input_ids = tokenizer.encode(input_text, return_tensors="pt", max_length=256, truncation=True)
    
    # Generate text with parameters matching your training setup
    outputs = model.generate(
        input_ids,
        max_length=256,
        num_return_sequences=1,
        no_repeat_ngram_size=2,
        top_k=30,
        top_p=0.9,
        temperature=0.7,
        do_sample=True,
        early_stopping=True,
        num_beams=4
    )
    
    # Decode and clean up the generated text
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return generated_text.strip()

iface = gr.Interface(
    fn=generate_text,
    inputs=gr.Textbox(lines=5, label="Input Text"),
    outputs=gr.Textbox(label="Generated Text"),
    title="Text Humanizer",
    description="Enter text to generate a more human-like version."
)

iface.launch()