You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
I am trying to use ChatGPT to create a Gradio app that can retrieve the data from Civitai for all the models I have acquired from Civitai, some of which I no longer use, and display them in a list. However, I am in need of assistance with what I currently have.
import gradio as gr
import os
import asyncio
from functools import lru_cache
import logging
import aiohttp
logging.basicConfig(level=logging.INFO)
@lru_cache(maxsize=128)
async def fetch_metadata(model_id):
logging.info(f"Fetching metadata for model {model_id}")
url = f"https://civitai.com/api/v1/models/{model_id}/lora-training-guide-steal-parameters-metadata-greater-hiperparametros-less"
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
if response.status == 200:
try:
metadata = await response.json()
logging.info(f"Received metadata for model {model_id}")
return {
"name": metadata.get("name"),
"description": metadata.get("description"),
"thumbnail": metadata.get("thumbnail"),
"link": metadata.get("link"),
}
except ValueError:
logging.error("Response is not in JSON format.")
return "Error: Response is not in JSON format."
else:
logging.error(f"Server returned status code {response.status}.")
return f"Error: Server returned status code {response.status}."
async def fetch_metadata_for_folder(folder_path):
logging.info(f"Fetching metadata for models in folder {folder_path}")
metadata_list = []
tasks = []
for filename in os.listdir(folder_path):
if filename.endswith(".safetensors"):
model_id = filename.split('.')[0] # assuming model ID is the filename without the extension
task = asyncio.ensure_future(fetch_metadata(model_id))
tasks.append(task)
responses = await asyncio.gather(*tasks)
for response in responses:
if response:
metadata_list.append(response)
return metadata_list
def scan_and_fetch_metadata(folder_path):
if not os.path.isdir(folder_path):
logging.error("Provided path is not a valid directory.")
return "Provided path is not a valid directory."
logging.info(f"Scanning folder {folder_path}")
metadata_list = asyncio.run(fetch_metadata_for_folder(folder_path))
if metadata_list:
logging.info("Successfully fetched metadata.")
return "\n".join(metadata_list)
else:
logging.info("No valid model information found in the specified folder.")
return "No valid model information found in the specified folder."
def civitai_metadata_app():
model_input = gr.components.Textbox(placeholder="Enter Model Folder Path")
scan_button = gr.components.Button("Scan and Fetch Metadata")
output_list = gr.components.Textbox()
def scan_and_fetch_metadata_callback(folder_path, _):
metadata_list = scan_and_fetch_metadata(folder_path)
return metadata_list
iface = gr.Interface(
fn=scan_and_fetch_metadata_callback,
inputs=[model_input, scan_button],
outputs=[output_list],
title="Civitai Model Metadata Fetcher",
description="Enter a model folder path to scan and fetch metadata from Civitai.",
live=False,
)
return iface
if __name__ == "__main__":
civitai_metadata_app().launch()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
I am trying to use ChatGPT to create a Gradio app that can retrieve the data from Civitai for all the models I have acquired from Civitai, some of which I no longer use, and display them in a list. However, I am in need of assistance with what I currently have.
Beta Was this translation helpful? Give feedback.
All reactions