joermd commited on
Commit
31dd1d0
·
verified ·
1 Parent(s): 12bc17e

Update reg.html

Browse files
Files changed (1) hide show
  1. reg.html +98 -47
reg.html CHANGED
@@ -602,67 +602,118 @@
602
  });
603
  });
604
 
605
- // دالة إرسال الطلبات لجميع الأقسام
606
  async function handleSubmit(section) {
607
  const container = document.getElementById(section);
608
  const resultDiv = container.querySelector(".response-container");
609
-
610
- // إذا كان القسم "analysis" وتوجد ملفات PDF مرفقة، نستخدم API رفع الملفات
611
  if (section === 'analysis') {
612
  const fileInput = container.querySelector("#analysisPDF");
 
 
 
 
 
 
 
613
  if (fileInput && fileInput.files && fileInput.files.length > 0) {
614
  const file = fileInput.files[0];
615
  console.log("Selected file:", file);
616
  let formData = new FormData();
617
  formData.append("file", file);
618
- resultDiv.innerHTML = '<div class="loading-spinner"></div>';
619
- try {
620
- const uploadResponse = await fetch('https://g2mgow5tgbxsjy-7777.proxy.runpod.net/proxy/8000/upload', {
621
- method: "POST",
622
- body: formData
623
- });
624
- console.log("Upload response:", uploadResponse);
625
- if (!uploadResponse.ok) {
626
  throw new Error("فشل رفع الملف");
627
  }
628
- const uploadData = await uploadResponse.json();
629
- console.log("Upload data:", uploadData);
630
- resultDiv.innerHTML = uploadData.response || "تم رفع الملف بنجاح";
631
- } catch (error) {
632
- console.error("Error uploading file:", error);
633
- resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ في رفع الملف. يرجى المحاولة مرة أخرى.</div>';
634
- }
635
- return; // عند التعامل مع الملف نتوقف هنا
 
636
  }
637
- }
638
-
639
- // إذا لم يوجد ملف (أو في الأقسام الأخرى) نستخدم النص المُدخل
640
- const textarea = container.querySelector("textarea");
641
- const text = textarea.value.trim();
642
- if (!text) {
643
- alert("الرجاء إدخال نص");
644
- return;
645
- }
646
- const payload = {
647
- message: getPromptPrefix(section) + text,
648
- history: []
649
- };
650
-
651
- resultDiv.innerHTML = '<div class="loading-spinner"></div>';
652
- try {
653
- const response = await fetch(API_URL, {
654
- method: "POST",
655
- headers: { "Content-Type": "application/json" },
656
- body: JSON.stringify(payload)
657
- });
658
- if (!response.ok) {
659
- throw new Error("فشل الاستجابة من الخادم");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  }
661
- const data = await response.json();
662
- resultDiv.innerHTML = data.response || "";
663
- } catch (error) {
664
- console.error("Error:", error);
665
- resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
666
  }
667
  }
668
 
 
602
  });
603
  });
604
 
605
+ // دالة إرسال الطلبات لقسم "التحليل القانوني"
606
  async function handleSubmit(section) {
607
  const container = document.getElementById(section);
608
  const resultDiv = container.querySelector(".response-container");
609
+
610
+ // إذا كان القسم "analysis" نتعامل مع احتمال وجود ملف ونص
611
  if (section === 'analysis') {
612
  const fileInput = container.querySelector("#analysisPDF");
613
+ const textArea = container.querySelector("textarea");
614
+ const text = textArea.value.trim();
615
+ // مسح المحتوى السابق
616
+ resultDiv.innerHTML = '';
617
+ let filePromise = null, textPromise = null;
618
+
619
+ // إذا تم إرفاق ملف PDF، نقوم برفعه وتحليله
620
  if (fileInput && fileInput.files && fileInput.files.length > 0) {
621
  const file = fileInput.files[0];
622
  console.log("Selected file:", file);
623
  let formData = new FormData();
624
  formData.append("file", file);
625
+ resultDiv.innerHTML += '<div id="fileAnalysisSpinner" class="loading-spinner"></div>';
626
+ filePromise = fetch('https://g2mgow5tgbxsjy-7777.proxy.runpod.net/proxy/8000/upload', {
627
+ method: "POST",
628
+ body: formData
629
+ })
630
+ .then(response => {
631
+ if (!response.ok) {
 
632
  throw new Error("فشل رفع الملف");
633
  }
634
+ return response.json();
635
+ })
636
+ .then(data => {
637
+ return data.response || "تم تحليل الملف بنجاح";
638
+ })
639
+ .catch(error => {
640
+ console.error("File analysis error:", error);
641
+ return '<div class="text-red-500">حدث خطأ في رفع الملف. يرجى المحاولة مرة أخرى.</div>';
642
+ });
643
  }
644
+
645
+ // إذا وُجد نص للتحليل (سواءً مع الملف أو بدونه) نرسله عبر API النصي
646
+ if (text) {
647
+ resultDiv.innerHTML += '<div id="textAnalysisSpinner" class="loading-spinner"></div>';
648
+ const payload = {
649
+ message: getPromptPrefix(section) + text,
650
+ history: []
651
+ };
652
+ textPromise = fetch(API_URL, {
653
+ method: "POST",
654
+ headers: { "Content-Type": "application/json" },
655
+ body: JSON.stringify(payload)
656
+ })
657
+ .then(response => {
658
+ if (!response.ok) {
659
+ throw new Error("فشل الاستجابة من الخادم");
660
+ }
661
+ return response.json();
662
+ })
663
+ .then(data => {
664
+ return data.response || "";
665
+ })
666
+ .catch(error => {
667
+ console.error("Text analysis error:", error);
668
+ return '<div class="text-red-500">حدث خطأ في تحليل النص. يرجى المحاولة مرة أخرى.</div>';
669
+ });
670
+ }
671
+
672
+ // انتظار انتهاء كلا العمليتين (إن وُجدتا)
673
+ const fileResult = filePromise ? await filePromise : null;
674
+ const textResult = textPromise ? await textPromise : null;
675
+
676
+ // مسح عناصر التحميل (spinners)
677
+ resultDiv.innerHTML = '';
678
+ if (fileResult) {
679
+ resultDiv.innerHTML += `<div><strong>نتيجة تحليل الملف:</strong><br>${fileResult}</div><br>`;
680
+ }
681
+ if (textResult) {
682
+ resultDiv.innerHTML += `<div><strong>نتيجة تحليل النص:</strong><br>${textResult}</div>`;
683
+ }
684
+ if (!fileResult && !textResult) {
685
+ alert("الرجاء إدخال نص أو إرفاق ملف PDF");
686
+ return;
687
+ }
688
+ } else {
689
+ // للأقسام الأخرى (بدون رفع ملفات)
690
+ const textarea = container.querySelector("textarea");
691
+ const text = textarea.value.trim();
692
+ if (!text) {
693
+ alert("الرجاء إدخال نص");
694
+ return;
695
+ }
696
+ const payload = {
697
+ message: getPromptPrefix(section) + text,
698
+ history: []
699
+ };
700
+
701
+ resultDiv.innerHTML = '<div class="loading-spinner"></div>';
702
+ try {
703
+ const response = await fetch(API_URL, {
704
+ method: "POST",
705
+ headers: { "Content-Type": "application/json" },
706
+ body: JSON.stringify(payload)
707
+ });
708
+ if (!response.ok) {
709
+ throw new Error("فشل الاستجابة من الخادم");
710
+ }
711
+ const data = await response.json();
712
+ resultDiv.innerHTML = data.response || "";
713
+ } catch (error) {
714
+ console.error("Error:", error);
715
+ resultDiv.innerHTML = '<div class="text-red-500">حدث خطأ. يرجى المحاولة مرة أخرى.</div>';
716
  }
 
 
 
 
 
717
  }
718
  }
719