Akbartus commited on
Commit
4bc9c57
·
1 Parent(s): bc2b59a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -1
app.py CHANGED
@@ -1,5 +1,38 @@
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.Interface.load("models/Akbartus/Lora360").launch(show_api=True)
4
 
5
 
 
1
+ # import gradio as gr
2
+
3
+ # gr.Interface.load("models/Akbartus/Lora360").launch(show_api=True)
4
+
5
  import gradio as gr
6
+ import torch
7
+ from PIL import Image
8
+ from torchvision.transforms import ToTensor, ToPILImage
9
+ from transformers import AutoModel
10
+
11
+ # Load the original model
12
+ original_model = gr.Interface.load("models/Akbartus/Lora360")
13
+
14
+ # Load the super-resolution model from Hugging Face's model hub
15
+ super_resolution_model = AutoModel.from_pretrained('CompVis/ldm-super-resolution-4x-openimages')
16
+
17
+ def process_image(input_image):
18
+ # Run the original model
19
+ output_image = original_model(input_image)
20
+
21
+ # Transform the output image to tensor
22
+ output_image = ToTensor()(output_image).unsqueeze(0)
23
+
24
+ # Ensure the super-resolution model is in eval mode and perform super-resolution
25
+ super_resolution_model.eval()
26
+ with torch.no_grad():
27
+ super_res_image = super_resolution_model(output_image)
28
+
29
+ # Convert the output tensor to an image
30
+ super_res_image = ToPILImage()(super_res_image[0])
31
+ return super_res_image
32
+
33
+ # Define the Gradio interface
34
+ iface = gr.Interface(fn=process_image, inputs="image", outputs="image")
35
+ iface.launch()
36
 
 
37
 
38