Open Adamchanadam opened 3 months ago
The problem is solved by adding the encoding="utf-8" into the create_or_modify_pyi() function in .\gradio\component_meta.py.
Four modifications are needed:
1 x Change source_file.read_text() to source_file.read_text(encoding="utf-8") once. 3 x Change pyi_file.read_text() to pyi_file.read_text(encoding='utf-8') three times.
def create_or_modify_pyi(
component_class: type, class_name: str, events: list[str | EventListener]
):
source_file = Path(inspect.getfile(component_class))
source_code = source_file.read_text(encoding="utf-8") # <---- add utf-8 here
current_impl, lineno = extract_class_source_code(source_code, class_name)
if not (current_impl and lineno):
raise ValueError("Couldn't find class source code")
new_interface = create_pyi(current_impl, events)
pyi_file = source_file.with_suffix(".pyi")
if not pyi_file.exists():
last_empty_line_before_class = -1
lines = source_code.splitlines()
for i, line in enumerate(lines):
if line in ["", " "]:
last_empty_line_before_class = i
if i >= lineno:
break
lines = (
lines[:last_empty_line_before_class]
+ ["from gradio.events import Dependency"]
+ lines[last_empty_line_before_class:]
)
with no_raise_exception():
pyi_file.write_text("\n".join(lines))
current_interface, _ = extract_class_source_code(pyi_file.read_text(encoding='utf-8'), class_name) # <---- add utf-8 here
if not current_interface:
with no_raise_exception():
with open(str(pyi_file), mode="a") as f:
f.write(new_interface)
else:
contents = pyi_file.read_text(encoding='utf-8') # <---- add utf-8 here
contents = contents.replace(current_interface, new_interface.strip())
current_contents = pyi_file.read_text(encoding='utf-8') # <---- add utf-8 here
if current_contents != contents:
with no_raise_exception():
pyi_file.write_text(contents)
Environment : Windows 11 (Conda) with Python 3.11.8 praisonAI 0.0.17
After installation ( : pip install praisonai
I ran the Initialise : praisonai --init create a movie script about dog in moon
it return error code as below , I think it's UTF-8 issue :