Spaces:
Running
Running
feat: add Gradio import handling and Windows compatibility for asyncio
Browse files- local_demo.py +18 -1
local_demo.py
CHANGED
|
@@ -7,11 +7,13 @@ Calistir:
|
|
| 7 |
|
| 8 |
from __future__ import annotations
|
| 9 |
|
|
|
|
| 10 |
import argparse
|
| 11 |
import csv
|
| 12 |
import json
|
| 13 |
import pickle
|
| 14 |
import socket
|
|
|
|
| 15 |
import time
|
| 16 |
import warnings
|
| 17 |
from collections import Counter
|
|
@@ -19,7 +21,22 @@ from dataclasses import dataclass
|
|
| 19 |
from pathlib import Path
|
| 20 |
from typing import Any
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
import numpy as np
|
| 24 |
|
| 25 |
from app.training.extract_features_batch import extract_sample_features
|
|
|
|
| 7 |
|
| 8 |
from __future__ import annotations
|
| 9 |
|
| 10 |
+
import asyncio
|
| 11 |
import argparse
|
| 12 |
import csv
|
| 13 |
import json
|
| 14 |
import pickle
|
| 15 |
import socket
|
| 16 |
+
import sys
|
| 17 |
import time
|
| 18 |
import warnings
|
| 19 |
from collections import Counter
|
|
|
|
| 21 |
from pathlib import Path
|
| 22 |
from typing import Any
|
| 23 |
|
| 24 |
+
if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"):
|
| 25 |
+
# Gradio/Uvicorn is more stable with the selector loop on Windows.
|
| 26 |
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
import gradio as gr
|
| 30 |
+
except ModuleNotFoundError as exc:
|
| 31 |
+
if exc.name == "gradio":
|
| 32 |
+
raise SystemExit(
|
| 33 |
+
"Gradio bu Python kurulumunda yok.\n"
|
| 34 |
+
f"Kullandigin yorumlayici: {sys.executable}\n"
|
| 35 |
+
"Kurulum komutu:\n"
|
| 36 |
+
f' "{sys.executable}" -m pip install -r requirements.txt'
|
| 37 |
+
) from exc
|
| 38 |
+
raise
|
| 39 |
+
|
| 40 |
import numpy as np
|
| 41 |
|
| 42 |
from app.training.extract_features_batch import extract_sample_features
|