朱东升 commited on
Commit
4f32597
·
1 Parent(s): 2f2f63e

requirements update6

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -2,8 +2,14 @@ import gradio as gr
2
  import json
3
  import importlib
4
  import os
 
5
  from pathlib import Path
6
 
 
 
 
 
 
7
  def evaluate(input_data):
8
  """评估代码的主函数
9
 
@@ -62,7 +68,12 @@ def evaluate_code(code, language):
62
  try:
63
  # 动态导入对应语言的评估模块
64
  module_name = f"src.eval_{language.lower()}"
65
- module = importlib.import_module(module_name)
 
 
 
 
 
66
 
67
  # 创建临时文件存储代码
68
  temp_dir = Path("temp")
@@ -81,8 +92,8 @@ def evaluate_code(code, language):
81
 
82
  return result
83
 
84
- except ImportError:
85
- return {"status": "Exception", "error": f"Language {language} not supported"}
86
  except Exception as e:
87
  return {"status": "Exception", "error": str(e)}
88
 
 
2
  import json
3
  import importlib
4
  import os
5
+ import sys
6
  from pathlib import Path
7
 
8
+ # 添加当前目录到模块搜索路径,确保可以导入src目录下的模块
9
+ current_dir = os.path.dirname(os.path.abspath(__file__))
10
+ if current_dir not in sys.path:
11
+ sys.path.append(current_dir)
12
+
13
  def evaluate(input_data):
14
  """评估代码的主函数
15
 
 
68
  try:
69
  # 动态导入对应语言的评估模块
70
  module_name = f"src.eval_{language.lower()}"
71
+ try:
72
+ module = importlib.import_module(module_name)
73
+ except ImportError:
74
+ # 尝试不带src前缀导入
75
+ module_name = f"eval_{language.lower()}"
76
+ module = importlib.import_module(module_name)
77
 
78
  # 创建临时文件存储代码
79
  temp_dir = Path("temp")
 
92
 
93
  return result
94
 
95
+ except ImportError as e:
96
+ return {"status": "Exception", "error": f"Language {language} not supported: {str(e)}"}
97
  except Exception as e:
98
  return {"status": "Exception", "error": str(e)}
99