Spaces:
Sleeping
Sleeping
add
Browse files193 unmodified lines19419519619719819920020120227 unmodified lines230231232233234235236237238239240193 unmodified linesasync def generate_viz(file: UploadFile = File(...), query: str = Form(...)):print("hello")try:contents = await file.read()excel_file = io.BytesIO(contents)df = pd.read_excel(excel_file)if query not in VALID_PLOTS:return JSONResponse(content={"error": f"Type de graphique invalide. Choisissez parmi : {', '.join(VALID_PLOTS)}"}, status_code=400)27 unmodified linesoutputs = codegen_model.generate(**inputs, max_new_tokens=120, pad_token_id=codegen_tokenizer.eos_token_id)generated_code = codegen_tokenizer.decode(outputs[0], skip_special_tokens=True).strip()generated_code = re.sub(r"(import matplotlib.pyplot as plt\nimport seaborn as sns\n)+", "import matplotlib.pyplot as plt\nimport seaborn as sns\n", generated_code)if generated_code.strip().endswith("sns."):generated_code = generated_code.rsplit("\n", 1)[0]print("🔹 Code généré par l'IA :\n", generated_code)try:compile(generated_code, "<string>", "exec")193 unmodified lines19419519619719819920020120227 unmodified lines230231232233234235236237238239240241242243244245246193 unmodified linesasync def generate_viz(file: UploadFile = File(...), query: str = Form(...)):print("hello")try:contents = await file.read()excel_file = io.BytesIO(contents)df = pd.read_excel(excel_file)if query not in VALID_PLOTS:return JSONResponse(content={"error": f"Type de graphique invalide. Choisissez parmi : {', '.join(VALID_PLOTS)}"}, status_code=400)27 unmodified linesoutputs = codegen_model.generate(**inputs, max_new_tokens=120, pad_token_id=codegen_tokenizer.eos_token_id)generated_code = codegen_tokenizer.decode(outputs[0], skip_special_tokens=True).strip()# 🔥 Nettoyage : couper si répétition du promptif "### Génère uniquement du code Python fonctionnel" in generated_code[1:]:generated_code = generated_code.split("### Génère uniquement du code Python fonctionnel")[0]# 🔥 Nettoyage : éviter doublon importsgenerated_code = re.sub(r"(import matplotlib.pyplot as plt\nimport seaborn as sns\n)+", "import matplotlib.pyplot as plt\nimport seaborn as sns\n", generated_code)if generated_code.strip().endswith("sns."):generated_code = generated_code.rsplit("\n", 1)[0]print("🔹 Code généré propre :\n", generated_code)try:compile(generated_code, "<string>", "exec")
app.py+10-4