import os os.system("pip install tensorflow") import gradio as gra import numpy as np import keras model = keras.models.load_model("text2seed-model") max_sequence_length = 1000 def podgotovka(text_input): text_input_encoded = [ord(char) for char in text_input.lower()] padded_input = np.zeros((1, max_sequence_length), dtype=np.int) padded_input[0, :len(text_input_encoded)] = text_input_encoded return padded_input def get_seed(text_input): padded_input = podgotovka(text_input) seed = model.predict(padded_input) seed = int(str(seed[0][0]).replace("0.", "")) print(seed) return seed def text2seed(text_input): return str(get_seed(text_input)) def text2randint(text_input): np.random.seed(get_seed(text_input)) number = np.random.randint(1, 10) return str(number) def text2random(text_input): np.random.seed(get_seed(text_input)) number = np.random.random() return str(number) text2seed_interface = gra.Interface(fn = text2seed, inputs="text", outputs="text") text2randint_interface = gra.Interface(fn = text2randint, inputs="text", outputs="text") text2random_interface = gra.Interface(fn = text2random, inputs="text", outputs="text") app = gra.Blocks() with app: gra.Markdown(""" # Welcome to the text2seed! Select the mode, enter text in text_input and enjoy the result! """) gra.TabbedInterface([text2seed_interface, text2randint_interface, text2random_interface], ["text2seed", "text2randint", "text2random"]) app.launch()