Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
|