File size: 795 Bytes
6fe7334
c07d108
 
 
6fe7334
cc7d8e3
 
c07d108
 
 
 
 
 
 
 
 
 
 
 
 
 
06a72bc
c07d108
 
 
 
 
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
import gradio as gr
# Load model directly
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("Dorjzodovsuren/mongolian-gpt2")
model = AutoModelForCausalLM.from_pretrained("Dorjzodovsuren/mongolian-gpt2", from_flax=True)

generation_params = {
    "do_sample": True,
    "temperature": 0.3,
    "top_p": 0.95,
    "top_k": 40,
    "max_new_tokens": 64,
    "repetition_penalty": 2.1
}

# Create a text generation pipeline
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, **generation_params)

def text_generator(text):
    return pipe(text)[0]["generated_text"]

demo = gr.Interface(fn=text_generator, inputs="textbox", outputs="textbox")
    
if __name__ == "__main__":
    demo.launch()