Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
from tensorflow.keras.preprocessing.text import tokenizer_from_json
|
6 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
7 |
+
|
8 |
+
# Load the trained model
|
9 |
+
model = load_model("text_to_wingdings_model_complex.h5")
|
10 |
+
|
11 |
+
# Load the tokenizer
|
12 |
+
with open("tokenizer.json") as json_file:
|
13 |
+
tokenizer = tokenizer_from_json(json_file.read())
|
14 |
+
|
15 |
+
# Function to convert text to Wingdings
|
16 |
+
def convert_to_wingdings(input_text):
|
17 |
+
# Preprocess the input text
|
18 |
+
text_sequence = tokenizer.texts_to_sequences([input_text])
|
19 |
+
max_length = 500 # Set to 500 as desired
|
20 |
+
text_sequence = pad_sequences(text_sequence, maxlen=max_length, padding='post')
|
21 |
+
|
22 |
+
# Predict the output
|
23 |
+
predictions = model.predict(text_sequence)
|
24 |
+
wingdings_sequence = np.argmax(predictions, axis=-1)
|
25 |
+
|
26 |
+
# Convert the sequence back to characters
|
27 |
+
wingdings_output = ''.join([tokenizer.index_word[i] for i in wingdings_sequence[0] if i != 0])
|
28 |
+
|
29 |
+
return wingdings_output
|
30 |
+
|
31 |
+
# Create Gradio interface
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=convert_to_wingdings,
|
34 |
+
inputs=gr.Textbox(label="Input Text", placeholder="Type your text here..."),
|
35 |
+
outputs=gr.Textbox(label="Wingdings Output"),
|
36 |
+
title="Text to Wingdings Converter",
|
37 |
+
description="Enter text to convert it to Wingdings."
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the interface
|
41 |
+
iface.launch()
|