geeaiml commited on
Commit
07c7c94
·
verified ·
1 Parent(s): 0d59d7e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -63
app.py DELETED
@@ -1,63 +0,0 @@
1
- import gradio as gr
2
- import pandas as pd
3
- import numpy as np
4
- from transformers import pipeline
5
- from sklearn.impute import SimpleImputer
6
- from sklearn.ensemble import IsolationForest
7
-
8
- # تحميل نموذج التلخيص من Hugging Face
9
- summarizer = pipeline("summarization", model="t5-small")
10
-
11
- def analyze_data_quality(file):
12
- df = pd.read_csv(file.name)
13
-
14
- # البحث عن القيم الناقصة
15
- missing_values = df.isnull().sum()
16
- missing_summary = missing_values[missing_values > 0].to_string()
17
-
18
- # البحث عن القيم الشاذة باستخدام Isolation Forest
19
- clf = IsolationForest(contamination=0.05, random_state=42)
20
- outliers = clf.fit_predict(df.select_dtypes(include=[np.number]))
21
- outlier_count = (outliers == -1).sum()
22
-
23
- # تلخيص النتائج
24
- report = f"🔍 تحليل جودة البيانات:\n\n"
25
- report += f"📌 عدد القيم الناقصة: {missing_values.sum()}\n"
26
- report += f"📌 عدد القيم الشاذة: {outlier_count}\n"
27
- report += "\n📊 تفاصيل القيم الناقصة:\n" + missing_summary if missing_summary else "\n✅ لا توجد قيم ناقصة."
28
-
29
- summary = summarizer(report, max_length=100, do_sample=False)[0]['summary_text']
30
-
31
- return summary
32
-
33
- def clean_data(file):
34
- df = pd.read_csv(file.name)
35
-
36
- # معالجة القيم الناقصة بالتعبئة
37
- imputer = SimpleImputer(strategy="mean")
38
- df[df.select_dtypes(include=[np.number]).columns] = imputer.fit_transform(df.select_dtypes(include=[np.number]))
39
-
40
- # إزالة القيم الشاذة
41
- clf = IsolationForest(contamination=0.05, random_state=42)
42
- outliers = clf.fit_predict(df.select_dtypes(include=[np.number]))
43
- df_cleaned = df[outliers != -1]
44
-
45
- cleaned_file = "cleaned_data.csv"
46
- df_cleaned.to_csv(cleaned_file, index=False)
47
- return cleaned_file
48
-
49
- # إنشاء واجهة Gradio
50
- with gr.Blocks() as app:
51
- gr.Markdown("## 🛠️ محلل جودة البيانات")
52
-
53
- file_input = gr.File(label="📂 رفع ملف CSV")
54
- analysis_output = gr.Textbox(label="📊 تقرير جودة البيانات")
55
- cleaned_file_output = gr.File(label="✅ تحميل البيانات المنظفة")
56
-
57
- analyze_button = gr.Button("🔍 تحليل الجودة")
58
- clean_button = gr.Button("🧹 تنظيف البيانات")
59
-
60
- analyze_button.click(analyze_data_quality, inputs=file_input, outputs=analysis_output)
61
- clean_button.click(clean_data, inputs=file_input, outputs=cleaned_file_output)
62
-
63
- app.launch()