Update app.py
Browse files
app.py
CHANGED
|
@@ -5,10 +5,17 @@ from pptx import Presentation
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import os, shutil, zipfile
|
| 7 |
|
| 8 |
-
# 🌟
|
| 9 |
-
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def extract_text(file_path):
|
| 13 |
text_blocks = []
|
| 14 |
if file_path.endswith('.pdf'):
|
|
@@ -43,8 +50,9 @@ def process_file(file):
|
|
| 43 |
tabs_html = []
|
| 44 |
tab_size = 5
|
| 45 |
tabs = [content[i:i+tab_size] for i in range(0,len(content),tab_size)]
|
|
|
|
| 46 |
for i, tab in enumerate(tabs,1):
|
| 47 |
-
html = f'<div id="tab{i}">\n'
|
| 48 |
html += f'<h3><img src="https://undraw.co/api/illustrations/undraw_education_f8ru.svg" width="40"> Tab {i}</h3>\n'
|
| 49 |
for j, para in enumerate(tab,1):
|
| 50 |
explanation = generate_explanation(para)
|
|
@@ -52,13 +60,56 @@ def process_file(file):
|
|
| 52 |
html += f'<p>{generate_quiz(para,j)}</p>\n'
|
| 53 |
html += '</div>'
|
| 54 |
tabs_html.append(html)
|
| 55 |
-
|
|
|
|
| 56 |
os.makedirs("project", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with open("project/index.html","w", encoding='utf-8') as f:
|
| 58 |
-
f.write("<html><head>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
for t in tabs_html:
|
| 60 |
f.write(t)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
f.write("</body></html>")
|
|
|
|
|
|
|
| 62 |
shutil.make_archive("academic_project","zip","project")
|
| 63 |
return "academic_project.zip"
|
| 64 |
|
|
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import os, shutil, zipfile
|
| 7 |
|
| 8 |
+
# 🌟 أخذ الـ Hugging Face Token من Secrets
|
| 9 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 10 |
|
| 11 |
+
# نموذج لتوليد الشرح
|
| 12 |
+
generator = pipeline(
|
| 13 |
+
"text-generation",
|
| 14 |
+
model="tiiuae/falcon-7b-instruct",
|
| 15 |
+
use_auth_token=HF_TOKEN
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# 📝 استخراج النصوص
|
| 19 |
def extract_text(file_path):
|
| 20 |
text_blocks = []
|
| 21 |
if file_path.endswith('.pdf'):
|
|
|
|
| 50 |
tabs_html = []
|
| 51 |
tab_size = 5
|
| 52 |
tabs = [content[i:i+tab_size] for i in range(0,len(content),tab_size)]
|
| 53 |
+
|
| 54 |
for i, tab in enumerate(tabs,1):
|
| 55 |
+
html = f'<div id="tab{i}" class="tab">\n'
|
| 56 |
html += f'<h3><img src="https://undraw.co/api/illustrations/undraw_education_f8ru.svg" width="40"> Tab {i}</h3>\n'
|
| 57 |
for j, para in enumerate(tab,1):
|
| 58 |
explanation = generate_explanation(para)
|
|
|
|
| 60 |
html += f'<p>{generate_quiz(para,j)}</p>\n'
|
| 61 |
html += '</div>'
|
| 62 |
tabs_html.append(html)
|
| 63 |
+
|
| 64 |
+
# إنشاء مجلد المشروع
|
| 65 |
os.makedirs("project", exist_ok=True)
|
| 66 |
+
|
| 67 |
+
# إنشاء ملف CSS
|
| 68 |
+
css_content = """
|
| 69 |
+
body { font-family: 'Cairo', sans-serif; background-color:#f5f7fa; color:#333; padding:20px; }
|
| 70 |
+
.tab { display:none; margin-bottom:40px; padding:20px; background:#e3f2fd; border-radius:10px; animation: fadein 1s; }
|
| 71 |
+
.ar { text-align:right; font-family:'Cairo', sans-serif; margin:10px 0; }
|
| 72 |
+
.en { text-align:left; font-family:'Open Sans', sans-serif; margin:5px 0 15px 0; color:#555; }
|
| 73 |
+
.tab-buttons { margin-bottom:20px; }
|
| 74 |
+
.tab-buttons button { margin-right:5px; padding:10px 15px; border:none; border-radius:5px; background:#90caf9; color:#fff; cursor:pointer; }
|
| 75 |
+
.tab-buttons button.active { background:#42a5f5; }
|
| 76 |
+
@keyframes fadein { from {opacity:0;} to {opacity:1;} }
|
| 77 |
+
"""
|
| 78 |
+
with open("project/style.css","w", encoding="utf-8") as f:
|
| 79 |
+
f.write(css_content)
|
| 80 |
+
|
| 81 |
+
# إنشاء ملف HTML
|
| 82 |
with open("project/index.html","w", encoding='utf-8') as f:
|
| 83 |
+
f.write("""<html><head>
|
| 84 |
+
<meta charset='utf-8'>
|
| 85 |
+
<title>Academic Project</title>
|
| 86 |
+
<link href="https://fonts.googleapis.com/css2?family=Cairo&family=Open+Sans&display=swap" rel="stylesheet">
|
| 87 |
+
<link rel="stylesheet" href="style.css">
|
| 88 |
+
</head><body>
|
| 89 |
+
<div class="tab-buttons">
|
| 90 |
+
""")
|
| 91 |
+
for i in range(1,len(tabs)+1):
|
| 92 |
+
f.write(f'<button onclick="showTab({i})" id="btn{i}">Tab {i}</button>')
|
| 93 |
+
f.write("</div>\n")
|
| 94 |
for t in tabs_html:
|
| 95 |
f.write(t)
|
| 96 |
+
|
| 97 |
+
# سكريبت للتنقل بين Tabs
|
| 98 |
+
f.write("""
|
| 99 |
+
<script>
|
| 100 |
+
function showTab(n){
|
| 101 |
+
var tabs = document.getElementsByClassName('tab');
|
| 102 |
+
var buttons = document.querySelectorAll('.tab-buttons button');
|
| 103 |
+
for(var i=0;i<tabs.length;i++){ tabs[i].style.display='none'; buttons[i].classList.remove('active'); }
|
| 104 |
+
document.getElementById('tab'+n).style.display='block';
|
| 105 |
+
document.getElementById('btn'+n).classList.add('active');
|
| 106 |
+
}
|
| 107 |
+
showTab(1); // عرض Tab الأول افتراضياً
|
| 108 |
+
</script>
|
| 109 |
+
""")
|
| 110 |
f.write("</body></html>")
|
| 111 |
+
|
| 112 |
+
# ضغط المشروع
|
| 113 |
shutil.make_archive("academic_project","zip","project")
|
| 114 |
return "academic_project.zip"
|
| 115 |
|