SUPERpuper commited on
Commit
f74a2cb
·
1 Parent(s): da6bf33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -33
app.py CHANGED
@@ -1,33 +1,21 @@
1
- import matplotlib.pyplot as plt
2
- import torch
3
-
4
- # Data for text to image conversion
5
- text = "This is a sample text to image converter application. It can convert various types of text, including names, numbers, and symbols, into images. Simply paste the text you wish to convert here and then run the program."
6
- image = torch.ones(len(text), height=128, width=128)
7
-
8
- # Create AI model
9
- model = transformers.AutoModel.from_pretrained("bert-base-uncased")
10
- model.load_state_dict(torch.load("model.pt"))
11
-
12
- # Generate new image data
13
- img = np.random.rand(image.shape)
14
- text = text.view(len(text), image)
15
-
16
- # Pass the new data through the model
17
- outputs = model(**input_data)
18
-
19
- # Reshape input tensors
20
- for batch in outputs["contain"]["feedforward"]:
21
- outputs["image"].append(torch.cat((batch[0]["view"], batch[1]["index"])))
22
-
23
- # Convert back to text
24
- final_output = np.stack(outputs["image"], axis=-1)
25
-
26
- # Print results
27
- output = final_output.numpy()
28
- print("Final output shape: ", output.shape)
29
-
30
- # Plot results
31
- output = image.reshape(output.shape).squeeze("i")
32
- plt.imshow(output)
33
- plt.show()
 
1
+ from keras.utils import simple_utils
2
+ from keras.models import Sequential
3
+ from keras.layers import Channels, Dense, Embedding, Concatenate, LSTM
4
+ from keras.layers import Reshape, Flatten
5
+ from keras.utils import plot_model
6
+
7
+ def text_to_image(text):
8
+ image = plot_model.generate_converting_function(
9
+ SimpleLeakyReLU(alpha=0.1),
10
+ inputs=['text', '-', 'color']
11
+ )
12
+ return image
13
+
14
+ def main():
15
+ text = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dictum porta quis massa aliquet, dictum pellentes volutpat. Duis vel elit metus, eget luctus imperdiet quis. Sed arcu eget eros massa, vehicula velit velit. Nam vitae mi eget felis pretium, in velit at fringilla luctus. Nulla luctus ligula dignissim arcu, at consequat elementum laoreet. In iaculis pellentes at metus. '
16
+ r.
17
+ c.
18
+ u.
19
+ '''
20
+ image = text_to_image(text)
21
+ return image