Kush26 commited on
Commit
2e28d6c
·
verified ·
1 Parent(s): 2c40e57

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from PIL import Image
4
+ from torchvision import transforms
5
+
6
+ # Load the pre-trained gram matrix
7
+ gram_matrix = torch.load("path_to_gram_matrix.pt")
8
+
9
+ def style_transfer(content_image):
10
+ # Preprocess the content image
11
+ preprocess = transforms.Compose([
12
+ transforms.Resize((256, 256)),
13
+ transforms.ToTensor(),
14
+ transforms.Lambda(lambda x: x.unsqueeze(0))
15
+ ])
16
+ content_image = preprocess(content_image)
17
+
18
+ # Apply style transfer using the pre-trained gram matrix
19
+ output_image = apply_style_transfer(content_image, gram_matrix)
20
+
21
+ # Convert tensor to PIL image for display
22
+ output_image = transforms.ToPILImage()(output_image.squeeze(0))
23
+ return output_image
24
+
25
+ # Define Gradio interface
26
+ iface = gr.Interface(fn=style_transfer,
27
+ inputs=gr.inputs.Image(),
28
+ outputs="image")
29
+
30
+ iface.launch()