import gradio as gr import asyncio from giskard.ml_worker.ml_worker import MLWorker from pydantic import AnyHttpUrl from giskard.settings import settings from urllib.parse import urlparse def run_ml_worker(url, api_key, hf_token): # Always run an external ML worker parsed_url = urlparse(url) backend_url = AnyHttpUrl( url=f"{parsed_url.scheme if parsed_url.scheme else 'http'}://{parsed_url.hostname}" f":{parsed_url.port if parsed_url.port else settings.ws_port}" f"/{parsed_url.path if parsed_url.path and len(parsed_url.path) else settings.ws_path}", scheme=parsed_url.scheme, host=parsed_url.hostname, port=parsed_url.port if parsed_url.port else settings.ws_port, path=parsed_url.path if parsed_url.path and len(parsed_url.path) else settings.ws_path, ) ml_worker = MLWorker(False, backend_url, api_key, hf_token) asyncio.get_event_loop().run_until_complete(ml_worker.start()) return "ML worker finished its work" iface = gr.Interface(fn=run_ml_worker, inputs=["text", "text", "text"], outputs="text") iface.launch()