Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,34 @@ ai_analyzer = pipeline(
|
|
8 |
)
|
9 |
|
10 |
ERROR_SUGGESTIONS = {
|
11 |
-
"SyntaxError":
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
"
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
|
20 |
def analyze_code(code):
|
@@ -25,13 +46,14 @@ def analyze_code(code):
|
|
25 |
except Exception as e:
|
26 |
error_type = type(e).__name__ # Hata tipini al
|
27 |
error_message = str(e) # Hata mesajı
|
28 |
-
suggestion = ERROR_SUGGESTIONS.get(error_type, "Bu hata için özel bir çözümümüz yok.")
|
29 |
|
30 |
# Yapay zeka destekli analiz
|
31 |
ai_prompt = f"Python'da {error_type} hatası ile ilgili detaylı açıklama ve çözüm önerisi ver."
|
32 |
ai_response = ai_analyzer(ai_prompt, max_length=150)[0]['generated_text']
|
33 |
|
34 |
-
|
|
|
35 |
|
36 |
# ✅ Kullanıcı Dostu Gradio Arayüzü
|
37 |
with gr.Blocks() as demo:
|
|
|
8 |
)
|
9 |
|
10 |
ERROR_SUGGESTIONS = {
|
11 |
+
"SyntaxError": {
|
12 |
+
"suggestion": "Kodun sözdiziminde hata var. Parantezleri veya iki nokta üst üste (:) işaretlerini kontrol edin.",
|
13 |
+
"example": "Doğru kullanım:\n```python\nprint('Merhaba Dünya!')\n```"
|
14 |
+
},
|
15 |
+
"NameError": {
|
16 |
+
"suggestion": "Tanımlanmamış bir değişken veya fonksiyon kullanılmış. Değişkeni veya fonksiyonu tanımladığınıza emin olun.",
|
17 |
+
"example": "Doğru kullanım:\n```python\nx = 5\nprint(x)\n```"
|
18 |
+
},
|
19 |
+
"IndentationError": {
|
20 |
+
"suggestion": "Girinti hatası var. Python, girintiye duyarlı olduğu için satır başlarını kontrol edin.",
|
21 |
+
"example": "Doğru kullanım:\n```python\nif True:\n print('Doğru girinti')\n```"
|
22 |
+
},
|
23 |
+
"TypeError": {
|
24 |
+
"suggestion": "Veri tipleri uyumsuz olabilir. Örneğin, bir string ile bir integer toplanamaz.",
|
25 |
+
"example": "Doğru kullanım:\n```python\nnumber = 5\ntext = 'Hello'\nresult = text + str(number)\nprint(result)\n```"
|
26 |
+
},
|
27 |
+
"ZeroDivisionError": {
|
28 |
+
"suggestion": "Bir sayıyı sıfıra bölemeyiz. Bölme işlemlerini kontrol edin.",
|
29 |
+
"example": "Doğru kullanım:\n```python\nx = 10\ny = 2\nresult = x / y\nprint(result)\n```"
|
30 |
+
},
|
31 |
+
"IndexError": {
|
32 |
+
"suggestion": "Dizinin (liste, tuple) olmayan bir indeksine erişmeye çalışıyorsunuz.",
|
33 |
+
"example": "Doğru kullanım:\n```python\nmy_list = [1, 2, 3]\nprint(my_list[2])\n```"
|
34 |
+
},
|
35 |
+
"KeyError": {
|
36 |
+
"suggestion": "Sözlükte (dictionary) olmayan bir anahtara erişmeye çalışıyorsunuz.",
|
37 |
+
"example": "Doğru kullanım:\n```python\nmy_dict = {'a': 1, 'b': 2}\nprint(my_dict['a'])\n```"
|
38 |
+
},
|
39 |
}
|
40 |
|
41 |
def analyze_code(code):
|
|
|
46 |
except Exception as e:
|
47 |
error_type = type(e).__name__ # Hata tipini al
|
48 |
error_message = str(e) # Hata mesajı
|
49 |
+
suggestion = ERROR_SUGGESTIONS.get(error_type, {"suggestion": "Bu hata için özel bir çözümümüz yok.", "example": ""})
|
50 |
|
51 |
# Yapay zeka destekli analiz
|
52 |
ai_prompt = f"Python'da {error_type} hatası ile ilgili detaylı açıklama ve çözüm önerisi ver."
|
53 |
ai_response = ai_analyzer(ai_prompt, max_length=150)[0]['generated_text']
|
54 |
|
55 |
+
# Çözüm önerisi ve doğru kullanım örneği
|
56 |
+
return f"❌ **{error_type} Hatası**:\n{error_message}\n\n💡 **Çözüm Önerisi:** {suggestion['suggestion']}\n\n📝 **Doğru Kullanım Örneği:**\n{suggestion['example']}\n\n🤖 **Yapay Zeka Açıklaması:** {ai_response}"
|
57 |
|
58 |
# ✅ Kullanıcı Dostu Gradio Arayüzü
|
59 |
with gr.Blocks() as demo:
|