Spaces:
Sleeping
Sleeping
Commit ·
49b8be3
1
Parent(s): 3534a12
Update app.py
Browse files
app.py
CHANGED
|
@@ -1 +1,34 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|