File size: 990 Bytes
df1aa82
4708837
 
e7aeb95
 
 
df1aa82
4708837
 
e7aeb95
 
 
 
 
 
 
 
18f1fae
e7aeb95
93b6465
4708837
df1aa82
4708837
df1aa82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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.path if parsed_url.path and len(parsed_url.path) else settings.ws_path}",
        scheme=parsed_url.scheme,
        host=parsed_url.hostname,
        path=parsed_url.path if parsed_url.path and len(parsed_url.path) else settings.ws_path,
    )
    print(f"Starting ML worker for {backend_url}")
    ml_worker = MLWorker(False, backend_url, api_key, hf_token)
    asyncio.run(ml_worker.start())
    return "ML worker finished its work"

iface = gr.Interface(fn=run_ml_worker, inputs=["text", "text", "text"], outputs="text")
iface.launch()