ASesYusuf1 commited on
Commit
2297009
·
verified ·
1 Parent(s): c6de5c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,4 +1,6 @@
1
- # Mevcut imports
 
 
2
  import os
3
  import sys
4
  import torch
@@ -18,28 +20,31 @@ import spaces
18
  import gdown
19
  import scipy.io.wavfile
20
  from pydub import AudioSegment
21
- import gc
22
 
23
- # Logging setup
24
  logging.basicConfig(level=logging.INFO)
25
  logger = logging.getLogger(__name__)
26
 
27
- # Mevcut CONFIG_DIR ve ensure_config_dir kaldırıldı (kullanılmıyor)
28
-
29
- # Mevcut JSON schema yaması (gerekirse korunabilir)
30
  original_json_schema_to_python_type = client_utils._json_schema_to_python_type
31
- def patched_json_schema_to_python_type(schema: any, defs: Optional[dict] = None) -> str:
 
32
  logger.debug(f"Parsing schema: {schema}")
33
  if isinstance(schema, bool):
 
34
  return "boolean"
35
  if not isinstance(schema, dict):
 
36
  return "Any"
37
  if "enum" in schema and schema.get("type") == "string":
 
38
  return f"Literal[{', '.join(repr(e) for e in schema['enum'])}]"
39
  try:
40
  return original_json_schema_to_python_type(schema, defs)
41
- except client_utils.APIInfoParseError:
 
42
  return "str"
 
43
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
44
 
45
  # Device setup
 
1
+ from typing import Optional, Any # Optional ve Any için gerekli içe aktarma
2
+
3
+ # Mevcut diğer içe aktarmalar (örneğin, önceki kodunuzdan)
4
  import os
5
  import sys
6
  import torch
 
20
  import gdown
21
  import scipy.io.wavfile
22
  from pydub import AudioSegment
 
23
 
24
+ # Logging setup (mevcut)
25
  logging.basicConfig(level=logging.INFO)
26
  logger = logging.getLogger(__name__)
27
 
28
+ # Gradio JSON schema yaması (düzeltilmiş)
 
 
29
  original_json_schema_to_python_type = client_utils._json_schema_to_python_type
30
+
31
+ def patched_json_schema_to_python_type(schema: Any, defs: Optional[dict] = None) -> str:
32
  logger.debug(f"Parsing schema: {schema}")
33
  if isinstance(schema, bool):
34
+ logger.info("Found boolean schema, returning 'boolean'")
35
  return "boolean"
36
  if not isinstance(schema, dict):
37
+ logger.warning(f"Unexpected schema type: {type(schema)}, returning 'Any'")
38
  return "Any"
39
  if "enum" in schema and schema.get("type") == "string":
40
+ logger.info(f"Handling enum schema: {schema['enum']}")
41
  return f"Literal[{', '.join(repr(e) for e in schema['enum'])}]"
42
  try:
43
  return original_json_schema_to_python_type(schema, defs)
44
+ except client_utils.APIInfoParseError as e:
45
+ logger.error(f"Failed to parse schema {schema}: {e}")
46
  return "str"
47
+
48
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
49
 
50
  # Device setup