ganna217 commited on
Commit
23c4271
·
1 Parent(s): dfb6307

Fix mobile responsiveness

Browse files
Files changed (2) hide show
  1. app.py +6 -13
  2. index.html +228 -81
app.py CHANGED
@@ -16,7 +16,7 @@ app.add_middleware(
16
  allow_headers=["*"],
17
  )
18
 
19
- # Serve static files (like Moon.PNG) under /assets
20
  app.mount("/assets", StaticFiles(directory="."), name="static")
21
 
22
  # Serve the HTML page at the root
@@ -44,17 +44,11 @@ async def summarize(request: Request):
44
  try:
45
  data = await request.json()
46
  text = data["text"]
47
- # Dynamic length based on input length
48
  input_length = len(summarizer.tokenizer(text)["input_ids"])
49
- # Set dynamic max_length (e.g., 50% of input with a cap at 150)
50
- max_length = min(150, max(50, int(input_length * 0.5)))
51
- # Set dynamic min_length (e.g., 20% of input with a floor at 20)
52
- min_length = max(20, int(input_length * 0.2))
53
- # Generate summary without fixed lengths if input is short
54
- if input_length < 50:
55
- summary = summarizer(text, do_sample=False)
56
- else:
57
- summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
58
  return {"summary": summary[0]["summary_text"]}
59
  except Exception as e:
60
  print(f"Error in summarize: {str(e)}")
@@ -73,13 +67,12 @@ async def translate(request: Request):
73
 
74
  # Perform translation
75
  result = translators[lang](text)
76
- print(f"Translation result for {lang}: {result}") # Debugging
77
 
78
  # Check if result is a list and has at least one item
79
  if not isinstance(result, list) or len(result) == 0:
80
  return {"error": "Translation failed: empty or invalid result"}
81
 
82
- # Extract the translated text (correct key is "translation_text")
83
  translation = result[0].get("translation_text")
84
  if translation is None:
85
  return {"error": "Translation failed: 'translation_text' not found in result"}
 
16
  allow_headers=["*"],
17
  )
18
 
19
+
20
  app.mount("/assets", StaticFiles(directory="."), name="static")
21
 
22
  # Serve the HTML page at the root
 
44
  try:
45
  data = await request.json()
46
  text = data["text"]
 
47
  input_length = len(summarizer.tokenizer(text)["input_ids"])
48
+ max_length = min(200, max(70, int(input_length * 0.7)))
49
+ min_length = max(30, int(input_length * 0.3))
50
+ # Generate summary
51
+ summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
 
 
 
 
 
52
  return {"summary": summary[0]["summary_text"]}
53
  except Exception as e:
54
  print(f"Error in summarize: {str(e)}")
 
67
 
68
  # Perform translation
69
  result = translators[lang](text)
70
+ print(f"Translation result for {lang}: {result}")
71
 
72
  # Check if result is a list and has at least one item
73
  if not isinstance(result, list) or len(result) == 0:
74
  return {"error": "Translation failed: empty or invalid result"}
75
 
 
76
  translation = result[0].get("translation_text")
77
  if translation is None:
78
  return {"error": "Translation failed: 'translation_text' not found in result"}
index.html CHANGED
@@ -8,45 +8,54 @@
8
  <style>
9
  * {
10
  box-sizing: border-box;
 
 
11
  }
12
- body {
13
  font-family: Arial, sans-serif;
14
  background-color: #000000;
15
  color: #e0e0e0;
16
  margin: 0;
17
- padding: 10px;
18
- min-height: 100vh;
 
 
 
 
19
  display: flex;
20
- justify-content: center;
21
- align-items: flex-start;
 
22
  }
23
  .container {
24
  max-width: 1000px;
25
  width: 100%;
 
26
  margin: 0 auto;
27
- padding: 0 10px;
28
  }
29
  .header {
30
  display: flex;
31
  align-items: center;
32
  justify-content: center;
33
  margin-bottom: 10px;
 
34
  }
35
  .header img {
36
- width: 50px;
37
  height: auto;
38
  margin-right: 10px;
39
  }
40
  .header h1 {
41
  font-family: 'Papyrus', sans-serif;
42
- font-size: 24px;
43
  margin: 0;
44
  color: #ffffff;
45
  text-shadow: 2px 2px 5px rgba(107, 72, 255, 0.5);
46
  }
47
  .tagline {
48
  font-family: 'Orbitron', sans-serif;
49
- font-size: 14px;
50
  font-weight: 700;
51
  color: #b0b0b0;
52
  text-align: center;
@@ -59,14 +68,16 @@
59
  flex-wrap: wrap;
60
  gap: 10px;
61
  margin-bottom: 20px;
 
62
  }
63
  .summarize-section div {
64
  flex: 1;
65
- min-width: 100%;
 
66
  }
67
  .summarize-section label {
68
  display: block;
69
- font-size: 16px;
70
  color: #ffffff;
71
  margin-bottom: 5px;
72
  }
@@ -75,20 +86,23 @@
75
  padding: 10px;
76
  border-radius: 5px;
77
  border: 2px solid #6b48ff;
78
- font-size: 14px; /* Reduced for mobile */
79
  background-color: #1a1a1a;
80
  color: #ffffff;
81
  box-shadow: 0 0 5px rgba(107, 72, 255, 0.3);
 
82
  }
83
  textarea {
84
- height: 150px;
85
  resize: vertical;
86
  }
87
  .output {
88
- height: 150px;
 
89
  }
90
  .translation-output {
91
- height: 100px;
 
92
  }
93
  .button-container {
94
  width: 100%;
@@ -98,14 +112,14 @@
98
  button {
99
  background: linear-gradient(90deg, #6b48ff, #a73aff);
100
  color: white;
101
- padding: 10px 20px;
102
  border: none;
103
- border-radius: 20px;
104
  cursor: pointer;
105
- font-size: 14px;
106
  transition: transform 0.2s, box-shadow 0.3s;
107
  box-shadow: 0 4px 10px rgba(107, 72, 255, 0.4);
108
- width: 100%;
109
  }
110
  button:hover {
111
  background: linear-gradient(90deg, #5a38e7, #9632e6);
@@ -120,20 +134,21 @@
120
  gap: 10px;
121
  align-items: center;
122
  margin-bottom: 10px;
 
123
  }
124
  .translate-section label {
125
- font-size: 16px;
126
  color: #ffffff;
127
  }
128
  select {
129
  padding: 8px;
130
  border-radius: 5px;
131
  border: 2px solid #a73aff;
132
- font-size: 14px;
133
  background-color: #1a1a1a;
134
  color: #ffffff;
135
  cursor: pointer;
136
- width: 100%;
137
  appearance: none;
138
  background-image: url('data:image/svg+xml;utf8,<svg fill="white" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
139
  background-repeat: no-repeat;
@@ -170,10 +185,10 @@
170
  font-size: 12px;
171
  }
172
  textarea, .output {
173
- height: 120px;
174
  }
175
  .translation-output {
176
- height: 80px;
177
  }
178
  button {
179
  padding: 8px 15px;
@@ -223,64 +238,196 @@
223
  </div>
224
  </div>
225
 
226
- <script>
227
- console.log("Script loaded successfully");
228
-
229
- async function summarize() {
230
- const text = document.getElementById("inputText").value;
231
- try {
232
- const controller = new AbortController();
233
- const timeoutId = setTimeout(() => controller.abort(), 120000);
234
- const response = await fetch("/summarize", {
235
- method: "POST",
236
- headers: { "Content-Type": "application/json" },
237
- body: JSON.stringify({ text: text }),
238
- signal: controller.signal
239
- });
240
- clearTimeout(timeoutId);
241
- const data = await response.json();
242
- console.log("Summarize response:", JSON.stringify(data, null, 2));
243
- if (data.summary) {
244
- document.getElementById("summary").innerText = data.summary;
245
- } else {
246
- document.getElementById("summary").innerText = "Error: " + (data.error || "No summary returned");
247
- }
248
- } catch (error) {
249
- console.error("Summarize error:", error);
250
- document.getElementById("summary").innerText = "Failed to summarize: " + error.message;
251
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
253
-
254
- async function doTranslate() {
255
- const summary = document.getElementById("summary").innerText;
256
- const lang = document.getElementById("language").value;
257
- if (lang === "default" || summary === "") {
258
- document.getElementById("translation").innerText = "Please select a language and ensure a summary is available.";
259
- return;
260
- }
261
- console.log("Translate called with lang:", lang, "Text:", summary);
262
- try {
263
- const controller = new AbortController();
264
- const timeoutId = setTimeout(() => controller.abort(), 120000);
265
- const response = await fetch("/translate", {
266
- method: "POST",
267
- headers: { "Content-Type": "application/json" },
268
- body: JSON.stringify({ text: summary, lang: lang }),
269
- signal: controller.signal
270
- });
271
- clearTimeout(timeoutId);
272
- const data = await response.json();
273
- console.log("Translate response:", JSON.stringify(data, null, 2));
274
- if (data.translation) {
275
- document.getElementById("translation").innerText = data.translation;
276
- } else {
277
- document.getElementById("translation").innerText = "Error: " + (data.error || "No translation returned");
278
- }
279
- } catch (error) {
280
- console.error("Translate error:", error);
281
- document.getElementById("translation").innerText = "Failed to translate: " + error.message;
282
- }
283
  }
284
- </script>
 
285
  </body>
286
  </html>
 
8
  <style>
9
  * {
10
  box-sizing: border-box;
11
+ margin: 0;
12
+ padding: 0;
13
  }
14
+ html, body {
15
  font-family: Arial, sans-serif;
16
  background-color: #000000;
17
  color: #e0e0e0;
18
  margin: 0;
19
+ padding: 0;
20
+ width: 100%;
21
+ height: auto;
22
+ overflow-y: auto;
23
+ }
24
+ body {
25
  display: flex;
26
+ flex-direction: column;
27
+ align-items: center;
28
+ padding: 10px;
29
  }
30
  .container {
31
  max-width: 1000px;
32
  width: 100%;
33
+ padding: 0 10px;
34
  margin: 0 auto;
35
+ box-sizing: border-box;
36
  }
37
  .header {
38
  display: flex;
39
  align-items: center;
40
  justify-content: center;
41
  margin-bottom: 10px;
42
+ width: 100%;
43
  }
44
  .header img {
45
+ width: 50px;
46
  height: auto;
47
  margin-right: 10px;
48
  }
49
  .header h1 {
50
  font-family: 'Papyrus', sans-serif;
51
+ font-size: 24px;
52
  margin: 0;
53
  color: #ffffff;
54
  text-shadow: 2px 2px 5px rgba(107, 72, 255, 0.5);
55
  }
56
  .tagline {
57
  font-family: 'Orbitron', sans-serif;
58
+ font-size: 14px;
59
  font-weight: 700;
60
  color: #b0b0b0;
61
  text-align: center;
 
68
  flex-wrap: wrap;
69
  gap: 10px;
70
  margin-bottom: 20px;
71
+ width: 100%;
72
  }
73
  .summarize-section div {
74
  flex: 1;
75
+ min-width: 100%;
76
+ width: 100%;
77
  }
78
  .summarize-section label {
79
  display: block;
80
+ font-size: 16px;
81
  color: #ffffff;
82
  margin-bottom: 5px;
83
  }
 
86
  padding: 10px;
87
  border-radius: 5px;
88
  border: 2px solid #6b48ff;
89
+ font-size: 14px;
90
  background-color: #1a1a1a;
91
  color: #ffffff;
92
  box-shadow: 0 0 5px rgba(107, 72, 255, 0.3);
93
+ box-sizing: border-box;
94
  }
95
  textarea {
96
+ height: 120px;
97
  resize: vertical;
98
  }
99
  .output {
100
+ height: 120px;
101
+ overflow-y: auto;
102
  }
103
  .translation-output {
104
+ height: 80px;
105
+ overflow-y: auto;
106
  }
107
  .button-container {
108
  width: 100%;
 
112
  button {
113
  background: linear-gradient(90deg, #6b48ff, #a73aff);
114
  color: white;
115
+ padding: 10px 20px;
116
  border: none;
117
+ border-radius: 20px;
118
  cursor: pointer;
119
+ font-size: 14px;
120
  transition: transform 0.2s, box-shadow 0.3s;
121
  box-shadow: 0 4px 10px rgba(107, 72, 255, 0.4);
122
+ width: 100%;
123
  }
124
  button:hover {
125
  background: linear-gradient(90deg, #5a38e7, #9632e6);
 
134
  gap: 10px;
135
  align-items: center;
136
  margin-bottom: 10px;
137
+ width: 100%;
138
  }
139
  .translate-section label {
140
+ font-size: 16px;
141
  color: #ffffff;
142
  }
143
  select {
144
  padding: 8px;
145
  border-radius: 5px;
146
  border: 2px solid #a73aff;
147
+ font-size: 14px;
148
  background-color: #1a1a1a;
149
  color: #ffffff;
150
  cursor: pointer;
151
+ width: 100%;
152
  appearance: none;
153
  background-image: url('data:image/svg+xml;utf8,<svg fill="white" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
154
  background-repeat: no-repeat;
 
185
  font-size: 12px;
186
  }
187
  textarea, .output {
188
+ height: 100px;
189
  }
190
  .translation-output {
191
+ height: 60px;
192
  }
193
  button {
194
  padding: 8px 15px;
 
238
  </div>
239
  </div>
240
 
241
+ <style>
242
+ * {
243
+ box-sizing: border-box;
244
+ margin: 0;
245
+ padding: 0;
246
+ }
247
+ html, body {
248
+ font-family: Arial, sans-serif;
249
+ background-color: #000000;
250
+ color: #e0e0e0;
251
+ margin: 0;
252
+ padding: 0;
253
+ width: 100%;
254
+ height: auto; /* Allow height to grow with content */
255
+ overflow-y: auto; /* Ensure scrolling is enabled */
256
+ }
257
+ body {
258
+ display: flex;
259
+ flex-direction: column;
260
+ align-items: center;
261
+ padding: 10px;
262
+ }
263
+ .container {
264
+ max-width: 1000px;
265
+ width: 100%;
266
+ padding: 0 10px;
267
+ margin: 0 auto;
268
+ box-sizing: border-box;
269
+ }
270
+ .header {
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: center;
274
+ margin-bottom: 10px;
275
+ width: 100%;
276
+ }
277
+ .header img {
278
+ width: 50px;
279
+ height: auto;
280
+ margin-right: 10px;
281
+ }
282
+ .header h1 {
283
+ font-family: 'Papyrus', sans-serif;
284
+ font-size: 24px;
285
+ margin: 0;
286
+ color: #ffffff;
287
+ text-shadow: 2px 2px 5px rgba(107, 72, 255, 0.5);
288
+ }
289
+ .tagline {
290
+ font-family: 'Orbitron', sans-serif;
291
+ font-size: 14px;
292
+ font-weight: 700;
293
+ color: #b0b0b0;
294
+ text-align: center;
295
+ margin-bottom: 20px;
296
+ letter-spacing: 1px;
297
+ }
298
+ /* Summarization Section */
299
+ .summarize-section {
300
+ display: flex;
301
+ flex-wrap: wrap;
302
+ gap: 10px;
303
+ margin-bottom: 20px;
304
+ width: 100%;
305
+ }
306
+ .summarize-section div {
307
+ flex: 1;
308
+ min-width: 100%;
309
+ width: 100%;
310
+ }
311
+ .summarize-section label {
312
+ display: block;
313
+ font-size: 16px;
314
+ color: #ffffff;
315
+ margin-bottom: 5px;
316
+ }
317
+ textarea, .output {
318
+ width: 100%;
319
+ padding: 10px;
320
+ border-radius: 5px;
321
+ border: 2px solid #6b48ff;
322
+ font-size: 14px;
323
+ background-color: #1a1a1a;
324
+ color: #ffffff;
325
+ box-shadow: 0 0 5px rgba(107, 72, 255, 0.3);
326
+ box-sizing: border-box;
327
+ }
328
+ textarea {
329
+ height: 120px;
330
+ resize: vertical;
331
+ }
332
+ .output {
333
+ height: 120px;
334
+ overflow-y: auto; /* Allow scrolling within the output */
335
+ }
336
+ .translation-output {
337
+ height: 80px;
338
+ overflow-y: auto;
339
+ }
340
+ .button-container {
341
+ width: 100%;
342
+ text-align: left;
343
+ margin-top: 5px;
344
+ }
345
+ button {
346
+ background: linear-gradient(90deg, #6b48ff, #a73aff);
347
+ color: white;
348
+ padding: 10px 20px;
349
+ border: none;
350
+ border-radius: 20px;
351
+ cursor: pointer;
352
+ font-size: 14px;
353
+ transition: transform 0.2s, box-shadow 0.3s;
354
+ box-shadow: 0 4px 10px rgba(107, 72, 255, 0.4);
355
+ width: 100%;
356
+ }
357
+ button:hover {
358
+ background: linear-gradient(90deg, #5a38e7, #9632e6);
359
+ transform: scale(1.05);
360
+ box-shadow: 0 6px 15px rgba(107, 72, 255, 0.6);
361
+ }
362
+ /* Translation Section */
363
+ .translate-section {
364
+ margin-top: 20px;
365
+ display: flex;
366
+ flex-wrap: wrap;
367
+ gap: 10px;
368
+ align-items: center;
369
+ margin-bottom: 10px;
370
+ width: 100%;
371
+ }
372
+ .translate-section label {
373
+ font-size: 16px;
374
+ color: #ffffff;
375
+ }
376
+ select {
377
+ padding: 8px;
378
+ border-radius: 5px;
379
+ border: 2px solid #a73aff;
380
+ font-size: 14px;
381
+ background-color: #1a1a1a;
382
+ color: #ffffff;
383
+ cursor: pointer;
384
+ width: 100%;
385
+ appearance: none;
386
+ background-image: url('data:image/svg+xml;utf8,<svg fill="white" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
387
+ background-repeat: no-repeat;
388
+ background-position: right 10px center;
389
+ }
390
+ select:focus {
391
+ outline: none;
392
+ border-color: #6b48ff;
393
+ }
394
+ /* Responsive Design */
395
+ @media (max-width: 768px) {
396
+ .summarize-section {
397
+ flex-direction: column;
398
  }
399
+ .summarize-section div {
400
+ min-width: 100%;
401
+ }
402
+ .translate-section {
403
+ flex-direction: column;
404
+ align-items: flex-start;
405
+ }
406
+ select {
407
+ width: 100%;
408
+ }
409
+ button {
410
+ width: 100%;
411
+ }
412
+ }
413
+ @media (max-width: 480px) {
414
+ .header h1 {
415
+ font-size: 20px;
416
+ }
417
+ .tagline {
418
+ font-size: 12px;
419
+ }
420
+ textarea, .output {
421
+ height: 100px;
422
+ }
423
+ .translation-output {
424
+ height: 60px;
425
+ }
426
+ button {
427
+ padding: 8px 15px;
428
+ font-size: 12px;
429
  }
430
+ }
431
+ </style>
432
  </body>
433
  </html>