user commited on
Commit
5dc5271
1 Parent(s): 11dcd61

Add random

Browse files
Files changed (1) hide show
  1. main.py +9 -1
main.py CHANGED
@@ -2,6 +2,13 @@ import gradio as gr
2
  import subprocess
3
  import os
4
  from datetime import datetime
 
 
 
 
 
 
 
5
 
6
  def convert_markdown_to_ppt(markdown_file, markdown_text, input_type, template_file=None):
7
  # 根據輸入類型處理 Markdown 檔案或字串
@@ -10,7 +17,8 @@ def convert_markdown_to_ppt(markdown_file, markdown_text, input_type, template_f
10
  else: # "Enter Markdown Text"
11
  # 將字串內容寫入暫存檔案
12
  timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
13
- input_path = f"/tmp/file_{timestamp}.md"
 
14
  with open(input_path, "w") as file:
15
  file.write(markdown_text)
16
 
 
2
  import subprocess
3
  import os
4
  from datetime import datetime
5
+ import random
6
+ import string
7
+
8
+ def generate_random_suffix(length=8):
9
+ # 生成指定長度的隨機字母或數字組合
10
+ characters = string.ascii_letters + string.digits
11
+ return ''.join(random.choice(characters) for _ in range(length))
12
 
13
  def convert_markdown_to_ppt(markdown_file, markdown_text, input_type, template_file=None):
14
  # 根據輸入類型處理 Markdown 檔案或字串
 
17
  else: # "Enter Markdown Text"
18
  # 將字串內容寫入暫存檔案
19
  timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
20
+ random_suffix = generate_random_suffix()
21
+ input_path = f"/tmp/file-{timestamp}-{random_suffix}.md"
22
  with open(input_path, "w") as file:
23
  file.write(markdown_text)
24