update
Browse files- app.py +6 -3
- core.py +23 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(
|
4 |
-
return
|
5 |
|
6 |
-
demo = gr.Interface(fn=greet, inputs="
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
+
from core import IQA
|
4 |
+
metric = IQA("nima-vgg16-ava")
|
5 |
|
6 |
+
def greet(image):
|
7 |
+
return metric(image).item()
|
8 |
|
9 |
+
demo = gr.Interface(fn=greet, inputs=gr.Image(format="png", image_mode="RGB", type="pil"), outputs=gr.Textbox())
|
10 |
demo.launch()
|
core.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import pyiqa
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class IQA:
|
6 |
+
def __init__(self, model_name="nima"):
|
7 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
8 |
+
self.model = pyiqa.create_metric(model_name, device=device)
|
9 |
+
print(self.model)
|
10 |
+
def __call__(self, image_path):
|
11 |
+
return self.model(image_path)
|
12 |
+
|
13 |
+
if __name__ == "__main__":
|
14 |
+
import requests
|
15 |
+
from PIL import Image
|
16 |
+
import glob
|
17 |
+
image_files = glob.glob("samples/*")
|
18 |
+
iqa_metric = IQA(model_name="nima-vgg16-ava")
|
19 |
+
for image_file in image_files:
|
20 |
+
print(image_file)
|
21 |
+
image = Image.open(image_file)
|
22 |
+
score = iqa_metric(image)
|
23 |
+
print(score)
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pyiqa
|