File size: 1,826 Bytes
a453475
 
1ded8ac
 
 
 
 
 
 
c280e3a
 
 
 
 
ab16f9b
0fd72b0
46c7b1e
 
 
ab16f9b
46c7b1e
 
ab16f9b
46c7b1e
 
9f7b778
107315a
 
 
72e16b4
 
643d4bb
 
 
46c7b1e
 
 
 
c120bb4
 
04ca987
0fd72b0
1ded8ac
a453475
 
 
 
 
0fd72b0
 
8d6db24
 
e92f3f5
a453475
0fd72b0
 
a453475
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
50
51
52
53
54
55
56
57
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)
    
    model_clear = model
    #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=id_check_point, output=output, quiet=False)

    #id_folder = "1zi3hSBRTP9uwHDVwQMqpGeXb8RBhJfrO"
    #gdown.download_folder(id=id_folder, quiet=True, use_cookies=False)

    # id = "1-CiBtOhzyVuiUGShONZqluey7TyX9-Y6"

    output = "total.h5"
    id = "1-KgcnP1ayWQ6l2-4h723JCYPoWxzOnU3"

    gdown.download(id=id, output=output, quiet=False)
    
    
    
    model.load_weights(output)
    #model = tf.keras.models.load_model(output)       
    
    return model_clear, model


def get_model():
    return pipeline('text-generation', model='gpt-2') 

def complete_text(start_of_sentence):

    result_clear = model_clear.generate(start_of_sentence, max_length=100)
    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_clear, result

model_clear, model  = download_model_NLP()
iface = gr.Interface(fn=complete_text, inputs=gr.inputs.Textbox(lines=2, placeholder='Start of Sentence Here...'), outputs=["text", "text"],)
iface.launch()