Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ load_dotenv()
|
|
12 |
openai.api_key = os.getenv('OPENAI_KEY')
|
13 |
|
14 |
def chat_with_model(prompts):
|
15 |
-
model = "gpt-3.5-turbo"
|
16 |
|
17 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
18 |
conversation.extend([{'role': 'user', 'content': prompt} for prompt in prompts])
|
@@ -23,17 +23,14 @@ def chat_with_model(prompts):
|
|
23 |
def generate_filename(prompt):
|
24 |
safe_date_time = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
25 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:50]
|
26 |
-
return f"{safe_date_time}_{safe_prompt}.
|
27 |
|
28 |
def create_file(filename, prompt, response):
|
29 |
with open(filename, 'w') as file:
|
30 |
-
file.write(f"Prompt
|
31 |
|
32 |
def get_table_download_link(file_path):
|
33 |
-
|
34 |
-
data = file.read()
|
35 |
-
b64 = base64.b64encode(data.encode()).decode()
|
36 |
-
href = f'<a href="data:file/txt;base64,{b64}" download="{os.path.basename(file_path)}">Download Response File</a>'
|
37 |
return href
|
38 |
|
39 |
def main():
|
@@ -59,8 +56,8 @@ def main():
|
|
59 |
|
60 |
st.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
61 |
|
62 |
-
|
63 |
-
for file in
|
64 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
65 |
|
66 |
if __name__ == "__main__":
|
|
|
12 |
openai.api_key = os.getenv('OPENAI_KEY')
|
13 |
|
14 |
def chat_with_model(prompts):
|
15 |
+
model = "gpt-3.5-turbo"
|
16 |
|
17 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
18 |
conversation.extend([{'role': 'user', 'content': prompt} for prompt in prompts])
|
|
|
23 |
def generate_filename(prompt):
|
24 |
safe_date_time = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
|
25 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:50]
|
26 |
+
return f"{safe_date_time}_{safe_prompt}.htm"
|
27 |
|
28 |
def create_file(filename, prompt, response):
|
29 |
with open(filename, 'w') as file:
|
30 |
+
file.write(f"<h1>Prompt:</h1> <p>{prompt}</p> <h1>Response:</h1> <p>{response}</p>")
|
31 |
|
32 |
def get_table_download_link(file_path):
|
33 |
+
href = f'<a href="{file_path}" target="_blank">{os.path.basename(file_path)}</a>'
|
|
|
|
|
|
|
34 |
return href
|
35 |
|
36 |
def main():
|
|
|
56 |
|
57 |
st.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
58 |
|
59 |
+
htm_files = glob.glob("*.htm")
|
60 |
+
for file in htm_files:
|
61 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
62 |
|
63 |
if __name__ == "__main__":
|