Spaces:
Paused
Paused
| import gradio as gr | |
| import numpy as np | |
| import pandas as pd | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing.text import tokenizer_from_json | |
| from tensorflow.keras.preprocessing.sequence import pad_sequences | |
| # Load the trained model | |
| model = load_model("text_to_wingdings_model_complex.h5") | |
| # Load the tokenizer | |
| with open("tokenizer.json") as json_file: | |
| tokenizer = tokenizer_from_json(json_file.read()) | |
| # Function to convert text to Wingdings | |
| def convert_to_wingdings(input_text): | |
| # Preprocess the input text | |
| text_sequence = tokenizer.texts_to_sequences([input_text]) | |
| max_length = 500 # Set to 500 as desired | |
| text_sequence = pad_sequences(text_sequence, maxlen=max_length, padding='post') | |
| # Predict the output | |
| predictions = model.predict(text_sequence) | |
| wingdings_sequence = np.argmax(predictions, axis=-1) | |
| # Convert the sequence back to characters | |
| wingdings_output = ''.join([tokenizer.index_word[i] for i in wingdings_sequence[0] if i != 0]) | |
| return wingdings_output | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=convert_to_wingdings, | |
| inputs=gr.Textbox(label="Input Text", placeholder="Type your text here..."), | |
| outputs=gr.Textbox(label="Wingdings Output"), | |
| title="Text to Wingdings Converter", | |
| description="Enter text to convert it to Wingdings." | |
| ) | |
| # Launch the interface | |
| iface.launch() | |