Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import traceback
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Hugging Face'ten büyük dil modeli yükleyelim
|
6 |
+
ai_analyzer = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct")
|
7 |
+
|
8 |
+
ERROR_SUGGESTIONS = {
|
9 |
+
"SyntaxError": "Kodun sözdiziminde hata var. Parantezleri veya iki nokta üst üste (:) işaretlerini kontrol edin.",
|
10 |
+
"NameError": "Tanımlanmamış bir değişken veya fonksiyon kullanılmış. Değişkeni veya fonksiyonu tanımladığınıza emin olun.",
|
11 |
+
"IndentationError": "Girinti hatası var. Python, girintiye duyarlı olduğu için satır başlarını kontrol edin.",
|
12 |
+
"TypeError": "Veri tipleri uyumsuz olabilir. Örneğin, bir string ile bir integer toplanamaz.",
|
13 |
+
"ZeroDivisionError": "Bir sayıyı sıfıra bölemeyiz. Bölme işlemlerini kontrol edin.",
|
14 |
+
"IndexError": "Dizinin (liste, tuple) olmayan bir indeksine erişmeye çalışıyorsunuz.",
|
15 |
+
"KeyError": "Sözlükte (dictionary) olmayan bir anahtara erişmeye çalışıyorsunuz.",
|
16 |
+
}
|
17 |
+
|
18 |
+
def analyze_code(code):
|
19 |
+
try:
|
20 |
+
exec(code, {}) # Güvenli şekilde kodu çalıştır
|
21 |
+
return "✅ Kod hatasız çalıştı!"
|
22 |
+
|
23 |
+
except Exception as e:
|
24 |
+
error_type = type(e).__name__ # Hata tipini al
|
25 |
+
error_message = str(e) # Hata mesajı
|
26 |
+
suggestion = ERROR_SUGGESTIONS.get(error_type, "Bu hata için özel bir çözümümüz yok.")
|
27 |
+
|
28 |
+
# Yapay zeka destekli analiz
|
29 |
+
ai_response = ai_analyzer(f"Python'da {error_type} hatası ile ilgili detaylı açıklama ve çözüm önerisi ver:", max_length=100)[0]['generated_text']
|
30 |
+
|
31 |
+
return f"❌ **{error_type} Hatası**:\n{error_message}\n\n💡 **Çözüm Önerisi:** {suggestion}\n\n🤖 **Yapay Zeka Açıklaması:** {ai_response}"
|
32 |
+
|
33 |
+
# ✅ Kullanıcı Dostu Gradio Arayüzü
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("## 🐍 Python Hata Analizcisi (Yapay Zeka Destekli)")
|
36 |
+
gr.Markdown("Python kodunuzu girin, hataları analiz edip çözüm önerileri sunalım!")
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
code_input = gr.Code(language="python", lines=10, label="📝 Kodunuzu Buraya Yazın:")
|
40 |
+
|
41 |
+
check_button = gr.Button("🚀 Analiz Et")
|
42 |
+
output_text = gr.Textbox(label="🔍 Sonuç", lines=10)
|
43 |
+
|
44 |
+
check_button.click(analyze_code, inputs=code_input, outputs=output_text)
|
45 |
+
|
46 |
+
demo.launch()
|