Skip to content

Commit

Permalink
Merge pull request #10 from GustavSO/dev
Browse files Browse the repository at this point in the history
Empty clipboard bug + minor errors
  • Loading branch information
GustavSO committed Jun 7, 2024
2 parents 0cd97b3 + 9c90613 commit 0d3198b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
11 changes: 7 additions & 4 deletions scripts/UI/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
class Card:
def __init__(
self,
title="name_placeholder",
creator="creator_placeholder",
type="type_placeholder",
visibility=True,
) -> None:
self.models: list[Model] = None
Expand Down Expand Up @@ -103,6 +100,10 @@ def get_components(self):
]

def get_updates(self):
# If no model is selected, don't update the UI
if not self.selected_model:
return [gr.update() for _ in range(10)]

name = namer.format_filename(
opts.mm_auto_naming_formatting, self.selected_model
)
Expand Down Expand Up @@ -150,7 +151,9 @@ def update_gallery(self):
def change_model(self, evt: gr.SelectData):
self.selected_model = self.models[evt.index]
if len(self.selected_model.images) > self.selected_image_index:
self.selected_image = self.selected_model.images[self.selected_image_index][0]
self.selected_image = self.selected_model.images[self.selected_image_index][
0
]
else:
self.selected_image = self.selected_model.images[0][0]
return self.get_updates()
Expand Down
21 changes: 11 additions & 10 deletions scripts/UI/single_model_page.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gradio as gr
from tkinter import Tk
from tkinter import Tk, TclError
from modules import shared
from scripts.mm_libs import downloader, loader
from scripts.mm_libs.debug import *
Expand All @@ -13,16 +13,17 @@ def fetch(input):
d_info("Testing URL found. Using it as input.")
input = shared.opts.mm_testing_model_url
elif shared.opts.mm_auto_paste:
input = Tk().clipboard_get()
try:
input = Tk().clipboard_get()
except TclError:
d_warn("Clipboard is empty, using current input as URL")
return input

models = downloader.fetch(input)
if models:
model_card.insert_models(models)
return model_card.get_updates() + [input]
else:
return gr.Textbox(value=input)


return input

with gr.Row():
model_url_input = gr.Textbox(
placeholder="Civitai URL or model ID",
Expand All @@ -40,7 +41,7 @@ def fetch(input):
fetch_btn.click(
fn=fetch,
inputs=model_url_input,
outputs=model_card.get_components() + [model_url_input],
outputs=model_url_input,
).then(
fn=model_card.get_updates, outputs=model_card.get_components()
).then(fn=model_card.update_gallery, outputs=model_card.model_gallery)


5 changes: 3 additions & 2 deletions scripts/mm_libs/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def d_error(text):
timestamp = datetime.now().strftime('%H:%M:%S:%f')[:-3]
if opts.mm_print_errors:
print(f"\033[91m[Model Manager ({timestamp})]\033[0m {text}")
gr.Error(text)
raise gr.Error(text)

def d_info(text):
timestamp = datetime.now().strftime('%H:%M:%S:%f')[:-3]
print(f"\033[92m[Model Manager ({timestamp})]\033[0m {text}")
if opts.mm_print_info:
print(f"\033[92m[Model Manager ({timestamp})]\033[0m {text}")
gr.Info(text)

0 comments on commit 0d3198b

Please sign in to comment.