Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,6 +38,17 @@ def generate_filename(prompt, file_type):
|
|
38 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:28]
|
39 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def truncate_document(document, length):
|
42 |
return document[:length]
|
43 |
|
|
|
38 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:28]
|
39 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
40 |
|
41 |
+
def create_file(filename, prompt, response):
|
42 |
+
if filename.endswith(".txt"):
|
43 |
+
with open(filename, 'w') as file:
|
44 |
+
file.write(f"Prompt:\n{prompt}\nResponse:\n{response}")
|
45 |
+
elif filename.endswith(".htm"):
|
46 |
+
with open(filename, 'w') as file:
|
47 |
+
file.write(f"<h1>Prompt:</h1> <p>{prompt}</p> <h1>Response:</h1> <p>{response}</p>")
|
48 |
+
elif filename.endswith(".md"):
|
49 |
+
with open(filename, 'w') as file:
|
50 |
+
file.write(f"# Prompt:\n{prompt}\n# Response:\n{response}")
|
51 |
+
|
52 |
def truncate_document(document, length):
|
53 |
return document[:length]
|
54 |
|