Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -9,6 +9,8 @@ import hashlib
|
|
9 |
import csv
|
10 |
import requests
|
11 |
import re
|
|
|
|
|
12 |
|
13 |
import gradio as gr
|
14 |
from pypinyin import lazy_pinyin
|
@@ -387,3 +389,42 @@ def find_n(lst, max_num):
|
|
387 |
return n - i -1
|
388 |
total = total - lst[i]
|
389 |
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
import csv
|
10 |
import requests
|
11 |
import re
|
12 |
+
import sys
|
13 |
+
import subprocess
|
14 |
|
15 |
import gradio as gr
|
16 |
from pypinyin import lazy_pinyin
|
|
|
389 |
return n - i -1
|
390 |
total = total - lst[i]
|
391 |
return 1
|
392 |
+
|
393 |
+
|
394 |
+
def run(command, desc=None, errdesc=None, custom_env=None, live=False):
|
395 |
+
if desc is not None:
|
396 |
+
print(desc)
|
397 |
+
if live:
|
398 |
+
result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
|
399 |
+
if result.returncode != 0:
|
400 |
+
raise RuntimeError(f"""{errdesc or 'Error running command'}.
|
401 |
+
Command: {command}
|
402 |
+
Error code: {result.returncode}""")
|
403 |
+
|
404 |
+
return ""
|
405 |
+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
|
406 |
+
if result.returncode != 0:
|
407 |
+
message = f"""{errdesc or 'Error running command'}.
|
408 |
+
Command: {command}
|
409 |
+
Error code: {result.returncode}
|
410 |
+
stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
|
411 |
+
stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
|
412 |
+
"""
|
413 |
+
raise RuntimeError(message)
|
414 |
+
return result.stdout.decode(encoding="utf8", errors="ignore")
|
415 |
+
|
416 |
+
def versions_html():
|
417 |
+
git = os.environ.get('GIT', "git")
|
418 |
+
python_version = ".".join([str(x) for x in sys.version_info[0:3]])
|
419 |
+
try:
|
420 |
+
commit_hash = run(f"{git} rev-parse HEAD").strip()
|
421 |
+
except Exception:
|
422 |
+
commit_hash = "<none>"
|
423 |
+
short_commit = commit_hash[0:7]
|
424 |
+
return f"""
|
425 |
+
Python: <span title="{sys.version}">{python_version}</span>
|
426 |
+
•
|
427 |
+
Gradio: {gr.__version__}
|
428 |
+
•
|
429 |
+
commit: <a style="text-decoration:none" href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/commit/{short_commit}">{short_commit}</a>
|
430 |
+
"""
|