Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -47,15 +47,22 @@ def chat_with_model(prompts):
|
|
47 |
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
48 |
return response['choices'][0]['message']['content']
|
49 |
|
50 |
-
def generate_filename(prompt):
|
51 |
central = pytz.timezone('US/Central')
|
52 |
safe_date_time = datetime.now(central).strftime("%m%d_%I_%M_%p")
|
53 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:30]
|
54 |
-
return f"{safe_date_time}_{safe_prompt}.
|
55 |
-
|
56 |
def create_file(filename, prompt, response):
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
def get_table_download_link_old(file_path):
|
61 |
with open(file_path, 'r') as file:
|
@@ -132,17 +139,17 @@ def main():
|
|
132 |
st.write('Response:')
|
133 |
st.write(response)
|
134 |
|
135 |
-
filename = generate_filename(user_prompt)
|
136 |
create_file(filename, user_prompt, response)
|
137 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
138 |
|
139 |
if len(file_content) > 0:
|
140 |
st.markdown(f"**File Content Added:**\n{file_content}")
|
141 |
|
142 |
-
|
143 |
-
for file in
|
144 |
st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
145 |
-
if st.sidebar.button(
|
146 |
os.remove(file)
|
147 |
st.experimental_rerun()
|
148 |
|
|
|
47 |
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
48 |
return response['choices'][0]['message']['content']
|
49 |
|
50 |
+
def generate_filename(prompt, file_type):
|
51 |
central = pytz.timezone('US/Central')
|
52 |
safe_date_time = datetime.now(central).strftime("%m%d_%I_%M_%p")
|
53 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:30]
|
54 |
+
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
55 |
+
|
56 |
def create_file(filename, prompt, response):
|
57 |
+
if filename.endswith(".txt"):
|
58 |
+
with open(filename, 'w') as file:
|
59 |
+
file.write(f"Prompt:\n{prompt}\nResponse:\n{response}")
|
60 |
+
elif filename.endswith(".htm"):
|
61 |
+
with open(filename, 'w') as file:
|
62 |
+
file.write(f"<h1>Prompt:</h1> <p>{prompt}</p> <h1>Response:</h1> <p>{response}</p>")
|
63 |
+
elif filename.endswith(".md"):
|
64 |
+
with open(filename, 'w') as file:
|
65 |
+
file.write(f"# Prompt:\n{prompt}\n# Response:\n{response}")
|
66 |
|
67 |
def get_table_download_link_old(file_path):
|
68 |
with open(file_path, 'r') as file:
|
|
|
139 |
st.write('Response:')
|
140 |
st.write(response)
|
141 |
|
142 |
+
filename = generate_filename(user_prompt, choice)
|
143 |
create_file(filename, user_prompt, response)
|
144 |
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
145 |
|
146 |
if len(file_content) > 0:
|
147 |
st.markdown(f"**File Content Added:**\n{file_content}")
|
148 |
|
149 |
+
all_files = glob.glob("*.txt") + glob.glob("*.htm") + glob.glob("*.md")
|
150 |
+
for file in all_files:
|
151 |
st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
152 |
+
if st.sidebar.button("π", key=file):
|
153 |
os.remove(file)
|
154 |
st.experimental_rerun()
|
155 |
|