chabane commited on
Commit
3358461
·
1 Parent(s): 196d42f

Updating UI

Browse files
main.py CHANGED
@@ -9,6 +9,7 @@ import io
9
  import base64
10
  import matplotlib.pyplot as plt
11
  from transformers import pipeline
 
12
  import fitz
13
  from docx import Document
14
  from pptx import Presentation
@@ -17,6 +18,8 @@ import PIL.Image as Image
17
 
18
  import fitz
19
 
 
 
20
  app=FastAPI()
21
  app.add_middleware(
22
  CORSMiddleware,
@@ -25,6 +28,23 @@ app.add_middleware(
25
  allow_methods=["*"],
26
  allow_headers=["*"],
27
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  app.mount("/static",StaticFiles(directory='static'),'static')
30
  templates = Jinja2Templates(directory='templates')
@@ -51,12 +71,13 @@ def caption(file:UploadFile=File(...)):
51
  if extension not in Supported_extensions:
52
  return {"error": "Unsupported file type"}
53
  image = Image.open(file.file)
54
- interpreter = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
55
  caption = interpreter(image)
56
  return {"caption": caption[0]['generated_text']}
57
 
58
  @app.post("/summerize")
59
  def summerzation(file:UploadFile=File(...)):
 
60
  extension = file.filename.split(".")[-1]
61
  if extension == "pdf":
62
  text = get_text_from_PDF(file.file)
@@ -70,7 +91,7 @@ def summerzation(file:UploadFile=File(...)):
70
  return {"error": "Unsupported file type"}
71
  if not text.strip():
72
  return {"error": "File is empty"}
73
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn",device=0)
74
  result=""
75
  for i in range(0,len(text),1024):
76
  result+=summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
@@ -111,7 +132,7 @@ error.
111
 
112
  ##Prompt: {prompt}.
113
  """
114
- generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct", device_map="auto")
115
  output = generator(message, max_length=1000)
116
  match = re.search(r'```python(.*?)```', output[0]["generated_text"], re.DOTALL)
117
  code =''
 
9
  import base64
10
  import matplotlib.pyplot as plt
11
  from transformers import pipeline
12
+
13
  import fitz
14
  from docx import Document
15
  from pptx import Presentation
 
18
 
19
  import fitz
20
 
21
+
22
+
23
  app=FastAPI()
24
  app.add_middleware(
25
  CORSMiddleware,
 
28
  allow_methods=["*"],
29
  allow_headers=["*"],
30
  )
31
+ try:
32
+ interpreter = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
33
+ except Exception as exp:
34
+ print("[ERROR] Can't load nlpconnect/vit-gpt2-image-captioning ")
35
+ print(str(exp))
36
+ try:
37
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn",device=0)
38
+ except Exception as exp:
39
+ print("[ERROR] Can't load facebook/bart-large-cnn ")
40
+ print(str(exp))
41
+ try:
42
+ generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct", device_map="auto")
43
+ except Exception as exp:
44
+ print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
45
+ print(str(exp))
46
+
47
+
48
 
49
  app.mount("/static",StaticFiles(directory='static'),'static')
50
  templates = Jinja2Templates(directory='templates')
 
71
  if extension not in Supported_extensions:
72
  return {"error": "Unsupported file type"}
73
  image = Image.open(file.file)
74
+
75
  caption = interpreter(image)
76
  return {"caption": caption[0]['generated_text']}
77
 
78
  @app.post("/summerize")
79
  def summerzation(file:UploadFile=File(...)):
80
+
81
  extension = file.filename.split(".")[-1]
82
  if extension == "pdf":
83
  text = get_text_from_PDF(file.file)
 
91
  return {"error": "Unsupported file type"}
92
  if not text.strip():
93
  return {"error": "File is empty"}
94
+
95
  result=""
96
  for i in range(0,len(text),1024):
97
  result+=summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
 
132
 
133
  ##Prompt: {prompt}.
134
  """
135
+
136
  output = generator(message, max_length=1000)
137
  match = re.search(r'```python(.*?)```', output[0]["generated_text"], re.DOTALL)
138
  code =''
static/assests/{webfonts/fa-regular-400.ttf → 1694502952506.jpg} RENAMED
File without changes
static/assests/webfonts/fa-regular-400.woff2 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:e3456d1283b9d75337a773dfd147bf908fd02c01b4bf48576d8603a69b13cbe5
3
- size 25472
 
 
 
 
static/assests/webfonts/fa-v4compatibility.ttf DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:30f6abf6baa425825828793d6dfad1fb63765d0e5abaa7af6feafb9bfcece5a0
3
- size 10836
 
 
 
 
static/assests/webfonts/fa-v4compatibility.woff2 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:0ce9033c69dc714f5f45ef9bf17d55e4c46bcdfad6799a4e92b38e7781bf86bd
3
- size 4796
 
 
 
 
static/scripts/dataViz.js CHANGED
@@ -52,7 +52,7 @@ form.addEventListener("submit", (e) => {
52
  e.preventDefault();
53
  const prompt = prompt_txt.value.trim();
54
  if (prompt && file) {
55
- showchart("../static/40185.jpg");
56
  } else {
57
  console.log("no file selected or no prompted");
58
  }
 
52
  e.preventDefault();
53
  const prompt = prompt_txt.value.trim();
54
  if (prompt && file) {
55
+ showchart("");
56
  } else {
57
  console.log("no file selected or no prompted");
58
  }
static/scripts/image_iterpretation.js ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const notifications = document.querySelector(".notifications");
2
+ const fileContainer = document.querySelector(".file-container");
3
+ const label = document.querySelector("#label-input");
4
+ const inputFile = document.querySelector("#document-input");
5
+ const form = document.querySelector("form");
6
+
7
+ const result_img = document.querySelector(".result_img");
8
+ const img_wrapper = document.querySelector(".img-wrapper");
9
+ const text_result = document.querySelector(".result-text");
10
+
11
+ const toast = (message, type) => {
12
+ const notification = document.createElement("div");
13
+
14
+ notification.innerHTML = `
15
+ <i class="fa fa-xmark close" onclick="this.parentNode.remove()"></i>
16
+ <i class="fa-solid ${
17
+ type === "error" ? "fa-circle-xmark" : "fa-triangle-exclamation"
18
+ } icon"></i>
19
+
20
+ <div class="notification-content">
21
+ <h3>${type}</h3>
22
+ <p>${message}</p>
23
+ </div>
24
+ `;
25
+ notification.classList.add(...["notification", type]);
26
+ notifications.appendChild(notification);
27
+ setTimeout(() => {
28
+ notification.remove();
29
+ }, 5000);
30
+ };
31
+
32
+ let file = null;
33
+ const SUPPORTED_EXT = ["jpg", "png", "jpeg"];
34
+
35
+ function clear() {
36
+ file = null;
37
+ label.style.display = "flex";
38
+ fileContainer.innerHTML = "";
39
+ }
40
+ const upload = (fileData) => {
41
+ file = fileData;
42
+ const ext = file.name.split(".").pop();
43
+ let isvalid = SUPPORTED_EXT.some((s_ext) => s_ext === ext);
44
+ if (isvalid) {
45
+ label.style.display = "none";
46
+ fileContainer.innerHTML = `
47
+ <div class="file-wrapper">
48
+ <i class="fa fa-file-image"></i>
49
+ <p>
50
+ ${file.name}
51
+ </p>
52
+ <button id='btn-clear' type="button" ><i class="fa fa-close" ></i></button>
53
+ </div>
54
+ `;
55
+ document
56
+ .querySelector("#btn-clear")
57
+ .addEventListener("click", (e) => clear(e));
58
+ } else {
59
+ console.error("file is not supported");
60
+ toast("file is not supported", "error");
61
+ }
62
+ };
63
+
64
+ inputFile.addEventListener("change", (e) => {
65
+ e.preventDefault();
66
+ if (inputFile.files[0]) upload(inputFile.files[0]);
67
+ });
68
+
69
+ label.addEventListener("dragover", (e) => {
70
+ e.preventDefault();
71
+ });
72
+ label.addEventListener("drop", (e) => {
73
+ e.preventDefault();
74
+ upload(e.dataTransfer.files[0]);
75
+ });
76
+ form.addEventListener("submit", async (e) => {
77
+ e.preventDefault();
78
+ let res = await new Promise((resolve, reject) => {
79
+ setTimeout(() => {
80
+ resolve({
81
+ src: "../static/assests/1694502952506.jpg",
82
+ discription: "this is a discription",
83
+ });
84
+ }, 3000);
85
+ });
86
+ const img = document.createElement("img");
87
+ img.src = res.src;
88
+ img_wrapper.appendChild(img);
89
+ text_result.innerText = res.discription;
90
+ result_img.scrollIntoView({ behavior: "smooth" });
91
+ });
static/styles/features.css CHANGED
@@ -138,7 +138,7 @@ header .container a {
138
 
139
  .steps {
140
  position: relative;
141
- height: 60vh;
142
  padding: 20px 0;
143
  overflow: hidden;
144
  }
@@ -159,6 +159,7 @@ header .container a {
159
  align-items: center;
160
  flex-wrap: wrap;
161
  gap: 30px;
 
162
  }
163
 
164
  .steps-content .steps-wrapper .step {
@@ -219,10 +220,13 @@ header .container a {
219
  justify-content: center;
220
  align-items: center;
221
  margin-bottom: 20px;
 
222
  }
223
 
224
  .upload .upload-content .wrapper .input-wrapper label {
225
- width: 350px;
 
 
226
  height: 150px;
227
  border-radius: 5px;
228
  border: 1px dashed var(--secondary);
@@ -252,10 +256,13 @@ header .container a {
252
 
253
  .upload .upload-content .wrapper .btn-wrapper {
254
  text-align: center;
 
255
  }
256
 
257
  .upload .upload-content .wrapper .btn-wrapper button {
258
- width: 350px;
 
 
259
  padding: 10px 0;
260
  cursor: pointer;
261
  font-size: 20px;
@@ -456,6 +463,38 @@ header .container a {
456
  border-radius: 5px;
457
  }
458
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  footer {
460
  font-family: R;
461
  height: 50px;
 
138
 
139
  .steps {
140
  position: relative;
141
+ min-height: fit-content;
142
  padding: 20px 0;
143
  overflow: hidden;
144
  }
 
159
  align-items: center;
160
  flex-wrap: wrap;
161
  gap: 30px;
162
+ margin-bottom: 50px;
163
  }
164
 
165
  .steps-content .steps-wrapper .step {
 
220
  justify-content: center;
221
  align-items: center;
222
  margin-bottom: 20px;
223
+ padding: 0 20px;
224
  }
225
 
226
  .upload .upload-content .wrapper .input-wrapper label {
227
+ width: 100%;
228
+ max-width: 350px;
229
+ min-width: 200px;
230
  height: 150px;
231
  border-radius: 5px;
232
  border: 1px dashed var(--secondary);
 
256
 
257
  .upload .upload-content .wrapper .btn-wrapper {
258
  text-align: center;
259
+ padding: 0 20px;
260
  }
261
 
262
  .upload .upload-content .wrapper .btn-wrapper button {
263
+ width: 100%;
264
+ max-width: 350px;
265
+ min-width: 200px;
266
  padding: 10px 0;
267
  cursor: pointer;
268
  font-size: 20px;
 
463
  border-radius: 5px;
464
  }
465
 
466
+ .result_img .result-content .img-wrapper {
467
+ display: flex;
468
+ justify-content: center;
469
+ align-items: center;
470
+ padding: 10px 0;
471
+ }
472
+
473
+ .result_img .result-content {
474
+ padding: 10px 0;
475
+ }
476
+
477
+ .result_img .result-content .img-wrapper img {
478
+ width: 300px;
479
+ height: 300px;
480
+ border-radius: 5px;
481
+
482
+ }
483
+
484
+ .result_img .result-content h3 {
485
+ font-size: 25px;
486
+ color: var(--primary);
487
+ margin-bottom: 5px;
488
+ }
489
+
490
+ .result_img .result-content p {
491
+ font-size: 17px;
492
+ letter-spacing: 2px;
493
+ color: var(--primary);
494
+ margin-bottom: 5px;
495
+
496
+ }
497
+
498
  footer {
499
  font-family: R;
500
  height: 50px;
templates/DataVisualisation.html CHANGED
@@ -6,7 +6,8 @@
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Data Visualisation</title>
8
  <link rel="stylesheet" href="static/styles/features.css" />
9
- <link rel="stylesheet" href="static/styles/all.min.css" />
 
10
  </head>
11
 
12
  <body>
@@ -100,13 +101,15 @@
100
  <div class="container result-content">
101
  <h1 class="title">Result</h1>
102
  <div class="chart-wrapper">
103
-
104
  </div>
105
  </div>
106
  </section>
107
  </main>
108
  <footer>SmartDoc AI - 2025</footer>
 
 
109
  <script src="static/scripts/dataViz.js"></script>
 
110
  </body>
111
 
112
  </html>
 
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Data Visualisation</title>
8
  <link rel="stylesheet" href="static/styles/features.css" />
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" />
10
+ <link rel="stylesheet" href="../static/styles/notification.css" />
11
  </head>
12
 
13
  <body>
 
101
  <div class="container result-content">
102
  <h1 class="title">Result</h1>
103
  <div class="chart-wrapper">
 
104
  </div>
105
  </div>
106
  </section>
107
  </main>
108
  <footer>SmartDoc AI - 2025</footer>
109
+ <div class="notifications">
110
+ </div>
111
  <script src="static/scripts/dataViz.js"></script>
112
+
113
  </body>
114
 
115
  </html>
templates/ImageInterpretation.html CHANGED
@@ -5,11 +5,14 @@
5
  <meta charset="UTF-8" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Image Interpretation</title>
8
- <link rel="stylesheet" href="static/styles/features.css" />
9
- <link rel="stylesheet" href="static/styles/all.min.css" />
 
10
  </head>
11
 
12
  <body>
 
 
13
  <header>
14
  <div class="container">
15
  <a href="/">SmartDoc AI </a>
@@ -90,8 +93,22 @@
90
  </form>
91
  </div>
92
  </section>
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </main>
94
  <footer>SmartDoc AI - 2025</footer>
 
95
  </body>
96
 
97
  </html>
 
5
  <meta charset="UTF-8" />
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Image Interpretation</title>
8
+ <link rel="stylesheet" href="../static/styles/features.css" />
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" />
10
+ <link rel="stylesheet" href="../static/styles/notification.css" />
11
  </head>
12
 
13
  <body>
14
+ <div class="notifications">
15
+ </div>
16
  <header>
17
  <div class="container">
18
  <a href="/">SmartDoc AI </a>
 
93
  </form>
94
  </div>
95
  </section>
96
+ <section id="result_img" class="result_img">
97
+ <div class="container result-content">
98
+ <h1 class="title">Result</h1>
99
+ <div class="img-wrapper">
100
+
101
+ </div>
102
+
103
+ <h3>Description : </h3>
104
+ <p class="result-text">
105
+ </p>
106
+
107
+ </div>
108
+ </section>
109
  </main>
110
  <footer>SmartDoc AI - 2025</footer>
111
+ <script src="../static/scripts/image_iterpretation.js"></script>
112
  </body>
113
 
114
  </html>
templates/Summarization.html CHANGED
@@ -6,10 +6,12 @@
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Summarization</title>
8
  <link rel="stylesheet" href="static/styles/features.css" />
9
- <link rel="stylesheet" href="static/styles/all.min.css" />
 
10
  </head>
11
 
12
  <body>
 
13
  <header>
14
  <div class="container">
15
  <a href="/">SmartDoc AI </a>
@@ -104,6 +106,8 @@
104
  </main>
105
 
106
  <footer>SmartDoc AI - 2025</footer>
 
 
107
  <script src="static/scripts/summerize.js"></script>
108
  </body>
109
 
 
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
  <title>SmartDoc AI-Summarization</title>
8
  <link rel="stylesheet" href="static/styles/features.css" />
9
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" />
10
+ <link rel="stylesheet" href="../static/styles/notification.css" />
11
  </head>
12
 
13
  <body>
14
+
15
  <header>
16
  <div class="container">
17
  <a href="/">SmartDoc AI </a>
 
106
  </main>
107
 
108
  <footer>SmartDoc AI - 2025</footer>
109
+ <div class="notifications">
110
+ </div>
111
  <script src="static/scripts/summerize.js"></script>
112
  </body>
113
 
templates/index.html CHANGED
@@ -64,7 +64,7 @@
64
  while retaining key information.
65
  </p>
66
  <div class="btn-wrapper">
67
- <a href="/sammarisation" class="btn">Try Now</a>
68
  </div>
69
  </div>
70
  <div class="feature">
 
64
  while retaining key information.
65
  </p>
66
  <div class="btn-wrapper">
67
+ <a href="/summarization" class="btn">Try Now</a>
68
  </div>
69
  </div>
70
  <div class="feature">