awacke1 commited on
Commit
3ae6978
·
1 Parent(s): 16504a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
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}.md"
27
 
28
  def create_file(filename, prompt, response):
29
  with open(filename, 'w') as file:
30
- file.write(f"Prompt: {prompt}\n\nResponse: {response}")
31
 
32
  def get_table_download_link(file_path):
33
- with open(file_path, 'r') as file:
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
- md_files = glob.glob("*.md")
63
- for file in md_files:
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__":