SUPERpuper commited on
Commit
49b8be3
·
1 Parent(s): 3534a12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -1 +1,34 @@
1
- import requests from PIL import Image def convert_text_to_image(text): # Try to find an image file that contains the text image_url = 'https://example.com/image.jpg' try: response = requests.get(image_url) image = Image.open(response.content) return image except: return None #Prompt the user to input a text text = input('Enter the text to convert to an image:') # Try to convert the text to an image if convert_text_to_image(text): print('The text was converted to an image!') else: print('The text could not be converted to an image.')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import matplotlib.pyplot as plt
3
+ import torch
4
+
5
+ # Data for text to image conversion
6
+ 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."
7
+ image = torch.ones(len(text), height=128, width=128)
8
+
9
+ # Create AI model
10
+ model = transformers.AutoModel.from_pretrained("bert-base-uncased")
11
+ model.load_state_dict(torch.load("model.pt"))
12
+
13
+ # Generate new image data
14
+ img = np.random.rand(image.shape)
15
+ text = text.view(len(text), image)
16
+
17
+ # Pass the new data through the model
18
+ outputs = model(**input_data)
19
+
20
+ # Reshape input tensors
21
+ for batch in outputs["contain"]["feedforward"]:
22
+ outputs["image"].append(torch.cat((batch[0]["view"], batch[1]["index"])))
23
+
24
+ # Convert back to text
25
+ final_output = np.stack(outputs["image"], axis=-1)
26
+
27
+ # Print results
28
+ output = final_output.numpy()
29
+ print("Final output shape: ", output.shape)
30
+
31
+ # Plot results
32
+ output = image.reshape(output.shape).squeeze("i")
33
+ plt.imshow(output)
34
+ plt.show()