bencser commited on
Commit
515c2a5
1 Parent(s): 011a663

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -2
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  import logging
3
  from groq import Groq
4
- from flask import Flask
5
  from dotenv import load_dotenv
6
 
7
  load_dotenv()
@@ -42,12 +42,67 @@ def generate_text():
42
  app.logger.error(f"Error generating text: {str(e)}")
43
  return "An error occurred while generating the text."
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Define Flask route
46
  @app.route("/")
47
  def home():
48
  try:
49
  message = generate_text()
50
- return f"<pre>{message}</pre>"
51
  except Exception as e:
52
  app.logger.error(f"Error in home route: {str(e)}")
53
  return "An error occurred. Please try again later.", 500
 
1
  import os
2
  import logging
3
  from groq import Groq
4
+ from flask import Flask, render_template_string
5
  from dotenv import load_dotenv
6
 
7
  load_dotenv()
 
42
  app.logger.error(f"Error generating text: {str(e)}")
43
  return "An error occurred while generating the text."
44
 
45
+ # HTML template
46
+ html_template = """
47
+ <!DOCTYPE html>
48
+ <html lang="en">
49
+ <head>
50
+ <meta charset="UTF-8">
51
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
52
+ <title>Silly Detention Letter Generator</title>
53
+ <style>
54
+ body {
55
+ font-family: Arial, sans-serif;
56
+ line-height: 1.6;
57
+ color: #333;
58
+ max-width: 800px;
59
+ margin: 0 auto;
60
+ padding: 20px;
61
+ background-color: #f4f4f4;
62
+ }
63
+ h1 {
64
+ color: #2c3e50;
65
+ text-align: center;
66
+ }
67
+ #letter {
68
+ background-color: white;
69
+ border: 1px solid #ddd;
70
+ padding: 20px;
71
+ border-radius: 5px;
72
+ white-space: pre-wrap;
73
+ margin-bottom: 20px;
74
+ }
75
+ #regenerate {
76
+ display: block;
77
+ width: 200px;
78
+ margin: 20px auto;
79
+ padding: 10px;
80
+ background-color: #3498db;
81
+ color: white;
82
+ border: none;
83
+ border-radius: 5px;
84
+ cursor: pointer;
85
+ font-size: 16px;
86
+ }
87
+ #regenerate:hover {
88
+ background-color: #2980b9;
89
+ }
90
+ </style>
91
+ </head>
92
+ <body>
93
+ <h1>Silly Detention Letter Generator</h1>
94
+ <div id="letter">{{ message }}</div>
95
+ <button id="regenerate" onclick="location.reload()">Regenerate Letter</button>
96
+ </body>
97
+ </html>
98
+ """
99
+
100
  # Define Flask route
101
  @app.route("/")
102
  def home():
103
  try:
104
  message = generate_text()
105
+ return render_template_string(html_template, message=message)
106
  except Exception as e:
107
  app.logger.error(f"Error in home route: {str(e)}")
108
  return "An error occurred. Please try again later.", 500