File size: 1,402 Bytes
551d64f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()