serhii-korobchenko's picture
Update app.py
9f7b778
raw
history blame
1.31 kB
import gradio as gr
from transformers import pipeline
import keras_nlp
import tensorflow as tf
import gdown
from tensorflow import keras
import time
def download_model_NLP():
preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset(
"gpt2_base_en",
sequence_length=128,)
model = keras_nlp.models.GPT2CausalLM.from_preset(
"gpt2_base_en", preprocessor=preprocessor)
output = "GPT2_keras_deer"
id_weights = "106fk9vGF_sHB8St9B2cKYE9jQVNSdKW_"
gdown.download(id=id_weights, output=output, quiet=False)
id_index = "10EWM2kJG4djpI5T6VLuj0UkGCbVIjmJx"
gdown.download(id=id_index, output=output, quiet=False)
id_check_point = "10Et7a0EzyrnnBhMWzt6frXLiNVm8a2qz"
gdown.download(id=check_point, output=output, quiet=False)
model.load_weights(output)
return model
def get_model():
return pipeline('text-generation', model='gpt-2')
def complete_text(start_of_sentence):
result = model.generate(start_of_sentence, max_length=100)
#result = model(start_of_sentence, max_length=50, do_sample=True)[0]['generated_text']
return result
model = download_model_NLP()
iface = gr.Interface(fn=complete_text, inputs=gr.inputs.Textbox(lines=2, placeholder='Start of Sentence Here...'), outputs="text")
iface.launch()