File size: 5,905 Bytes
794b7d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>AI-Powered Web App</title>
  <style>

    :root {

      --primary-color: #4A90E2;

      --secondary-color: #f4f6f8;

      --text-color: #333;

      --btn-color: #4A90E2;

      --btn-hover: #357ABD;

      --card-bg: #fff;

      --card-shadow: rgba(0, 0, 0, 0.1);

      --border-radius: 8px;

      --transition: 0.3s;

      --max-width: 900px;

    }

    * {

      box-sizing: border-box;

    }

    body {

      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

      color: var(--text-color);

      background: var(--secondary-color);

      margin: 0;

      padding: 20px;

      display: flex;

      justify-content: center;

    }

    .container {

      width: 100%;

      max-width: var(--max-width);

    }

    h1 {

      text-align: center;

      color: var(--primary-color);

      margin-bottom: 40px;

    }

    .section {

      background: var(--card-bg);

      padding: 20px;

      margin-bottom: 30px;

      border-radius: var(--border-radius);

      box-shadow: 0 2px 8px var(--card-shadow);

      transition: transform var(--transition);

    }

    .section:hover {

      transform: translateY(-3px);

    }

    h2 {

      margin-top: 0;

      color: var(--primary-color);

      border-bottom: 2px solid var(--secondary-color);

      padding-bottom: 5px;

    }

    label {

      display: block;

      margin-top: 15px;

      font-weight: bold;

    }

    input[type="file"], input[type="text"], button, textarea {

      width: 100%;

      padding: 10px;

      margin-top: 8px;

      border: 1px solid #ccc;

      border-radius: var(--border-radius);

      font-size: 1rem;

    }

    button {

      background: var(--btn-color);

      color: #fff;

      border: none;

      margin-top: 20px;

      padding: 12px;

      font-size: 1rem;

      border-radius: var(--border-radius);

      cursor: pointer;

      transition: background var(--transition);

    }

    button:hover {

      background: var(--btn-hover);

    }

    .results {

      margin-top: 20px;

      padding: 15px;

      background: var(--secondary-color);

      border-radius: var(--border-radius);

      border: 1px solid #ddd;

      min-height: 60px;

    }

    @media (min-width: 768px) {

      .grid {

        display: flex;

        gap: 20px;

      }

      .grid > div {

        flex: 1;

      }

    }

  </style>
</head>
<body>
  <div class="container">
    <h1>AI-Powered Web Application</h1>

    <!-- Function 1 & 2 in grid on larger screens -->
    <div class="grid">
      <!-- Function 1: Document & Image Analysis -->
      <div class="section" id="analysis-section">
        <h2>1. Document & Image Analysis</h2>
        <!-- Text Summarization -->
        <label for="doc-input-summarize">Upload Document (PDF, DOCX, PPTX, XLSX):</label>
        <input type="file" id="doc-input-summarize" accept=".pdf,.docx,.pptx,.xlsx" />
        <button id="summarize-btn">Summarize Document</button>
        <div class="results" id="summary-result">Your summary will appear here.</div>

        <!-- Image Captioning -->
        <label for="img-input-caption">Upload Image (JPG, PNG):</label>
        <input type="file" id="img-input-caption" accept="image/*" />
        <button id="caption-btn">Generate Caption</button>
        <div class="results" id="caption-result">Image caption will appear here.</div>
      </div>

      <!-- Function 2: Intelligent Question Answering -->
      <div class="section" id="qa-section">
        <h2>2. Intelligent Question Answering</h2>
        <label for="file-input-qa">Upload Document or Image:</label>
        <input type="file" id="file-input-qa" accept=".pdf,.docx,.pptx,.xlsx,image/*" />
        <label for="question-input">Enter Your Question:</label>
        <input type="text" id="question-input" placeholder="Type your question here..." />
        <button id="qa-btn">Ask Question</button>
        <div class="results" id="qa-result">Answer will appear here.</div>
      </div>
    </div>

    <script>

      async function sendData(url, fileInput, extraData, resultContainer) {

        const file = fileInput.files[0];

        if (!file) {

          resultContainer.textContent = 'Please select a file.';

          return;

        }

        const formData = new FormData();

        formData.append('file', file);

        if (extraData) Object.keys(extraData).forEach(key => formData.append(key, extraData[key]));

        resultContainer.textContent = 'Processing...';

        try {

          const res = await fetch(url, { method: 'POST', body: formData });

          const data = await res.json();

          resultContainer.textContent = data.result || JSON.stringify(data);

        } catch (err) {

          resultContainer.textContent = 'Error: ' + err.message;

        }

      }

      document.getElementById('summarize-btn').addEventListener('click', () => {

        sendData('/api/summarize', document.getElementById('doc-input-summarize'), null, document.getElementById('summary-result'));

      });

      document.getElementById('caption-btn').addEventListener('click', () => {

        sendData('/api/caption', document.getElementById('img-input-caption'), null, document.getElementById('caption-result'));

      });

      document.getElementById('qa-btn').addEventListener('click', () => {

        const q = document.getElementById('question-input').value.trim();

        if (!q) { document.getElementById('qa-result').textContent = 'Please enter a question.'; return; }

        sendData('/api/qa', document.getElementById('file-input-qa'), { question: q }, document.getElementById('qa-result'));

      });

    </script>
  </div>
</body>
</html>