Some improvements
Browse files- docker-compose.yml +1 -0
- docker/Dockerfile +1 -0
- images/cat.jpg +0 -0
- requirements.txt +1 -1
- src/app.py +1 -0
- src/pages/interrogation.py +9 -5
- src/pages/logs.py +3 -3
- src/repositories/images.py +5 -5
- src/scenarios/interrogation.py +5 -5
- src/storage/state.py +4 -0
docker-compose.yml
CHANGED
|
@@ -6,6 +6,7 @@ services:
|
|
| 6 |
build:
|
| 7 |
context: .
|
| 8 |
dockerfile: ./docker/Dockerfile
|
|
|
|
| 9 |
environment:
|
| 10 |
GRADIO_SERVER_NAME: 0.0.0.0
|
| 11 |
GRADIO_SERVER_PORT: 7860
|
|
|
|
| 6 |
build:
|
| 7 |
context: .
|
| 8 |
dockerfile: ./docker/Dockerfile
|
| 9 |
+
command: ["gradio", "app.py", "--demo-name=app"]
|
| 10 |
environment:
|
| 11 |
GRADIO_SERVER_NAME: 0.0.0.0
|
| 12 |
GRADIO_SERVER_PORT: 7860
|
docker/Dockerfile
CHANGED
|
@@ -28,6 +28,7 @@ RUN apt-get install -y --no-install-recommends libssl-dev libffi-dev
|
|
| 28 |
|
| 29 |
COPY ./app.py /app/app.py
|
| 30 |
COPY ./src /app/src/
|
|
|
|
| 31 |
|
| 32 |
COPY ./requirements.txt /tmp/requirements.txt
|
| 33 |
|
|
|
|
| 28 |
|
| 29 |
COPY ./app.py /app/app.py
|
| 30 |
COPY ./src /app/src/
|
| 31 |
+
COPY ./images /app/images/
|
| 32 |
|
| 33 |
COPY ./requirements.txt /tmp/requirements.txt
|
| 34 |
|
images/cat.jpg
ADDED
|
requirements.txt
CHANGED
|
@@ -4,7 +4,7 @@ fairscale
|
|
| 4 |
ftfy
|
| 5 |
Pillow
|
| 6 |
timm
|
| 7 |
-
transformers==4.
|
| 8 |
open_clip_torch==2.14.0
|
| 9 |
requests
|
| 10 |
clip-interrogator==0.5.4
|
|
|
|
| 4 |
ftfy
|
| 5 |
Pillow
|
| 6 |
timm
|
| 7 |
+
transformers==4.37.2
|
| 8 |
open_clip_torch==2.14.0
|
| 9 |
requests
|
| 10 |
clip-interrogator==0.5.4
|
src/app.py
CHANGED
|
@@ -11,4 +11,5 @@ def run():
|
|
| 11 |
app = gr.TabbedInterface([interrogation_page, logs_page], [
|
| 12 |
"Interrogation", "Logs"
|
| 13 |
])
|
|
|
|
| 14 |
app.queue().launch(show_error=True)
|
|
|
|
| 11 |
app = gr.TabbedInterface([interrogation_page, logs_page], [
|
| 12 |
"Interrogation", "Logs"
|
| 13 |
])
|
| 14 |
+
|
| 15 |
app.queue().launch(show_error=True)
|
src/pages/interrogation.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from src.storage.state import state as State
|
|
|
|
| 4 |
|
| 5 |
from src.scenarios.interrogation import image_analysis, image_to_prompt
|
| 6 |
from src.repositories.images import images as ImagesRepo
|
|
@@ -36,12 +37,13 @@ CSS = """
|
|
| 36 |
"""
|
| 37 |
|
| 38 |
|
| 39 |
-
def select_image(
|
| 40 |
-
|
| 41 |
-
State.set_current_image(
|
| 42 |
|
| 43 |
|
| 44 |
def selected_image_process():
|
|
|
|
| 45 |
image_path = State.get_current_image()
|
| 46 |
if not image_path:
|
| 47 |
gr.Warning("No image selected!")
|
|
@@ -62,10 +64,12 @@ def build():
|
|
| 62 |
elem_id="gallery",
|
| 63 |
columns=[2], rows=[2],
|
| 64 |
object_fit="contain",
|
| 65 |
-
height=
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
-
gallery.
|
| 69 |
button = gr.Button("Analyze")
|
| 70 |
|
| 71 |
with gr.Column():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from src.storage.state import state as State
|
| 4 |
+
from src.modules.logger import logger as Logger
|
| 5 |
|
| 6 |
from src.scenarios.interrogation import image_analysis, image_to_prompt
|
| 7 |
from src.repositories.images import images as ImagesRepo
|
|
|
|
| 37 |
"""
|
| 38 |
|
| 39 |
|
| 40 |
+
def select_image(selection: gr.SelectData):
|
| 41 |
+
Logger.info("Image selected")
|
| 42 |
+
State.set_current_image(selection.value['image']['path'])
|
| 43 |
|
| 44 |
|
| 45 |
def selected_image_process():
|
| 46 |
+
Logger.info("Selected image process")
|
| 47 |
image_path = State.get_current_image()
|
| 48 |
if not image_path:
|
| 49 |
gr.Warning("No image selected!")
|
|
|
|
| 64 |
elem_id="gallery",
|
| 65 |
columns=[2], rows=[2],
|
| 66 |
object_fit="contain",
|
| 67 |
+
height=800,
|
| 68 |
+
allow_preview=False,
|
| 69 |
+
selected_index=None,
|
| 70 |
)
|
| 71 |
|
| 72 |
+
gallery.select(select_image, inputs=None, outputs=None)
|
| 73 |
button = gr.Button("Analyze")
|
| 74 |
|
| 75 |
with gr.Column():
|
src/pages/logs.py
CHANGED
|
@@ -16,7 +16,7 @@ def test(message):
|
|
| 16 |
|
| 17 |
|
| 18 |
def build():
|
| 19 |
-
with gr.Blocks() as
|
| 20 |
gr.Markdown(
|
| 21 |
"""
|
| 22 |
# Logs page!
|
|
@@ -28,6 +28,6 @@ def build():
|
|
| 28 |
add_btn.click(fn=read_logs, outputs=logs_element)
|
| 29 |
clear_btn = gr.Button("Clean")
|
| 30 |
clear_btn.click(fn=clear_logs, outputs=logs_element)
|
| 31 |
-
|
| 32 |
|
| 33 |
-
return
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def build():
|
| 19 |
+
with gr.Blocks() as block:
|
| 20 |
gr.Markdown(
|
| 21 |
"""
|
| 22 |
# Logs page!
|
|
|
|
| 28 |
add_btn.click(fn=read_logs, outputs=logs_element)
|
| 29 |
clear_btn = gr.Button("Clean")
|
| 30 |
clear_btn.click(fn=clear_logs, outputs=logs_element)
|
| 31 |
+
block.load(read_logs, None, logs_element, every=10)
|
| 32 |
|
| 33 |
+
return block
|
src/repositories/images.py
CHANGED
|
@@ -6,11 +6,11 @@ class Images:
|
|
| 6 |
|
| 7 |
def __init__(self):
|
| 8 |
self.images = [
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
]
|
| 15 |
|
| 16 |
def get_images(self):
|
|
|
|
| 6 |
|
| 7 |
def __init__(self):
|
| 8 |
self.images = [
|
| 9 |
+
"/app/images/cat.jpg",
|
| 10 |
+
"/app/images/cat.jpg",
|
| 11 |
+
"/app/images/cat.jpg",
|
| 12 |
+
"/app/images/cat.jpg",
|
| 13 |
+
"/app/images/cat.jpg"
|
| 14 |
]
|
| 15 |
|
| 16 |
def get_images(self):
|
src/scenarios/interrogation.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
-
from src.modules.clip_model_loader import clip_model_loader as ClipModelLoader
|
| 4 |
from src.storage.state import state as State
|
| 5 |
|
| 6 |
|
| 7 |
def image_to_prompt(image_path):
|
| 8 |
-
|
| 9 |
result = ClipModelLoader.image_to_prompt(image_path)
|
| 10 |
-
|
| 11 |
return result
|
| 12 |
|
| 13 |
|
| 14 |
def image_analysis(image_path):
|
| 15 |
-
|
| 16 |
result = ClipModelLoader.image_analyse(image_path)
|
| 17 |
-
|
| 18 |
return result
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
from src.modules.models.clip_model_loader import clip_model_loader as ClipModelLoader
|
| 4 |
from src.storage.state import state as State
|
| 5 |
|
| 6 |
|
| 7 |
def image_to_prompt(image_path):
|
| 8 |
+
State.begin()
|
| 9 |
result = ClipModelLoader.image_to_prompt(image_path)
|
| 10 |
+
State.end()
|
| 11 |
return result
|
| 12 |
|
| 13 |
|
| 14 |
def image_analysis(image_path):
|
| 15 |
+
State.begin()
|
| 16 |
result = ClipModelLoader.image_analyse(image_path)
|
| 17 |
+
State.end()
|
| 18 |
return result
|
src/storage/state.py
CHANGED
|
@@ -16,6 +16,10 @@ class State:
|
|
| 16 |
# Prediction
|
| 17 |
self._current_image = None
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# State begin - end
|
| 20 |
def begin(self):
|
| 21 |
self._check_lock_assert()
|
|
|
|
| 16 |
# Prediction
|
| 17 |
self._current_image = None
|
| 18 |
|
| 19 |
+
def _check_lock_assert(self):
|
| 20 |
+
if self._lock:
|
| 21 |
+
raise Exception('State locked')
|
| 22 |
+
|
| 23 |
# State begin - end
|
| 24 |
def begin(self):
|
| 25 |
self._check_lock_assert()
|