bencser commited on
Commit
1f13911
·
verified ·
1 Parent(s): 29685b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -18,8 +18,13 @@ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
18
  model = "llama-3.1-70b-versatile"
19
 
20
  # Define function to generate text
21
- def generate_text(parent_name, child_name):
22
- prompt = f"Generate a concise silly letter to {parent_name} about their child {child_name}'s detention reasons. Write extreme behaviours in posh British English used in private schools."
 
 
 
 
 
23
  try:
24
  completion = client.chat.completions.create(
25
  model=model,
@@ -76,7 +81,7 @@ html_template = """
76
  border-radius: 5px;
77
  margin-bottom: 20px;
78
  }
79
- input[type="text"] {
80
  width: 100%;
81
  padding: 10px;
82
  margin-bottom: 10px;
@@ -102,15 +107,18 @@ html_template = """
102
  </head>
103
  <body>
104
  <h1>Silly Detention Letter Generator</h1>
 
105
  <form method="post">
106
  <input type="text" name="parent_name" placeholder="Parent's Name" required>
107
  <input type="text" name="child_name" placeholder="Child's Name" required>
 
 
 
 
 
108
  <input type="submit" value="Generate Letter">
109
  </form>
110
- {% if message %}
111
- <div id="letter">{{ message }}</div>
112
  <button id="regenerate" onclick="location.reload()">Regenerate Letter</button>
113
- {% endif %}
114
  </body>
115
  </html>
116
  """
@@ -122,9 +130,13 @@ def home():
122
  if request.method == "POST":
123
  parent_name = request.form["parent_name"]
124
  child_name = request.form["child_name"]
125
- message = generate_text(parent_name, child_name)
126
  else:
127
- message = None
 
 
 
 
128
  return render_template_string(html_template, message=message)
129
  except Exception as e:
130
  app.logger.error(f"Error in home route: {str(e)}")
 
18
  model = "llama-3.1-70b-versatile"
19
 
20
  # Define function to generate text
21
+ def generate_text(parent_name, child_name, language):
22
+ prompts = {
23
+ "posh": f"Generate a concise silly letter to {parent_name} about their child {child_name}'s detention reasons. Write extreme behaviours in posh British English used in private schools.",
24
+ "english": f"Generate a concise silly letter to {parent_name} about their child {child_name}'s detention reasons. Write extreme behaviours in standard English.",
25
+ "hungarian": f"Generate a concise silly letter to {parent_name} about their child {child_name}'s detention reasons. Write extreme behaviours in Hungarian."
26
+ }
27
+ prompt = prompts[language]
28
  try:
29
  completion = client.chat.completions.create(
30
  model=model,
 
81
  border-radius: 5px;
82
  margin-bottom: 20px;
83
  }
84
+ input[type="text"], select {
85
  width: 100%;
86
  padding: 10px;
87
  margin-bottom: 10px;
 
107
  </head>
108
  <body>
109
  <h1>Silly Detention Letter Generator</h1>
110
+ <div id="letter">{{ message }}</div>
111
  <form method="post">
112
  <input type="text" name="parent_name" placeholder="Parent's Name" required>
113
  <input type="text" name="child_name" placeholder="Child's Name" required>
114
+ <select name="language" required>
115
+ <option value="posh">Posh British English (Private School)</option>
116
+ <option value="english">Standard English</option>
117
+ <option value="hungarian">Hungarian</option>
118
+ </select>
119
  <input type="submit" value="Generate Letter">
120
  </form>
 
 
121
  <button id="regenerate" onclick="location.reload()">Regenerate Letter</button>
 
122
  </body>
123
  </html>
124
  """
 
130
  if request.method == "POST":
131
  parent_name = request.form["parent_name"]
132
  child_name = request.form["child_name"]
133
+ language = request.form["language"]
134
  else:
135
+ parent_name = "Mr. and Mrs. Smith"
136
+ child_name = "John"
137
+ language = "posh"
138
+
139
+ message = generate_text(parent_name, child_name, language)
140
  return render_template_string(html_template, message=message)
141
  except Exception as e:
142
  app.logger.error(f"Error in home route: {str(e)}")