Minor changes on app.py
Browse files
app.py
CHANGED
|
@@ -27,16 +27,18 @@ def save_model_state(state):
|
|
| 27 |
json.dump(state, f)
|
| 28 |
|
| 29 |
def list_available_models():
|
| 30 |
-
"""List all .pth models in the models directory"""
|
| 31 |
if not os.path.exists(MODELS_DIR):
|
| 32 |
return []
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
def get_hf_model_list():
|
| 36 |
-
"""Get list of model files from HuggingFace repository"""
|
| 37 |
try:
|
| 38 |
files = list_repo_files(HF_REPO_ID)
|
| 39 |
-
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
print(f"Error fetching models from HuggingFace: {str(e)}")
|
| 42 |
return []
|
|
@@ -108,7 +110,7 @@ def create_interface():
|
|
| 108 |
fn=lambda x: "No models found in ./models directory. Please train a model first.",
|
| 109 |
inputs="image",
|
| 110 |
outputs="text",
|
| 111 |
-
title="TeLVE - Turkish efficient Language Vision Engine",
|
| 112 |
description="Error: No models available"
|
| 113 |
)
|
| 114 |
|
|
@@ -119,11 +121,11 @@ def create_interface():
|
|
| 119 |
gr.Dropdown(choices=available_models, label="Select Model", value=available_models[0])
|
| 120 |
],
|
| 121 |
outputs=gr.Textbox(label="Generated Caption"),
|
| 122 |
-
title="TeLVE - Turkish Language Vision
|
| 123 |
-
description="Upload an image to generate a Turkish
|
| 124 |
examples=[
|
| 125 |
-
["./images/
|
| 126 |
-
["./images/
|
| 127 |
] if os.path.exists("./images") else None
|
| 128 |
)
|
| 129 |
return interface
|
|
|
|
| 27 |
json.dump(state, f)
|
| 28 |
|
| 29 |
def list_available_models():
|
| 30 |
+
"""List all .pth models in the models directory in reverse order"""
|
| 31 |
if not os.path.exists(MODELS_DIR):
|
| 32 |
return []
|
| 33 |
+
models = [f for f in os.listdir(MODELS_DIR) if f.endswith('.pth')]
|
| 34 |
+
return sorted(models, reverse=True)
|
| 35 |
|
| 36 |
def get_hf_model_list():
|
| 37 |
+
"""Get list of model files from HuggingFace repository in reverse order"""
|
| 38 |
try:
|
| 39 |
files = list_repo_files(HF_REPO_ID)
|
| 40 |
+
models = [f.split('/')[-1] for f in files if f.startswith('models/') and f.endswith('.pth')]
|
| 41 |
+
return sorted(models, reverse=True)
|
| 42 |
except Exception as e:
|
| 43 |
print(f"Error fetching models from HuggingFace: {str(e)}")
|
| 44 |
return []
|
|
|
|
| 110 |
fn=lambda x: "No models found in ./models directory. Please train a model first.",
|
| 111 |
inputs="image",
|
| 112 |
outputs="text",
|
| 113 |
+
title="TeLVE - Turkish efficient Language Vision Engine 🧿",
|
| 114 |
description="Error: No models available"
|
| 115 |
)
|
| 116 |
|
|
|
|
| 121 |
gr.Dropdown(choices=available_models, label="Select Model", value=available_models[0])
|
| 122 |
],
|
| 123 |
outputs=gr.Textbox(label="Generated Caption"),
|
| 124 |
+
title="TeLVE - Turkish efficient Language Vision Engine 🧿",
|
| 125 |
+
description="Upload an image to generate a Turkish description.",
|
| 126 |
examples=[
|
| 127 |
+
["./images/mugla.jpg", available_models[0]],
|
| 128 |
+
["./images/example.jpg", available_models[0]]
|
| 129 |
] if os.path.exists("./images") else None
|
| 130 |
)
|
| 131 |
return interface
|