Felix92 commited on
Commit
cc2aa56
·
1 Parent(s): bae6c77

update to multifile

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -59,16 +59,25 @@ def handle_uploads(font_upload, wordlist_upload, agree):
59
  if not agree:
60
  return gr.Markdown("You must agree to the terms and conditions before proceeding."), None, None, None
61
 
 
 
 
 
 
62
  try:
63
- if font_upload:
64
- font_path = Path(font_upload)
 
65
  font_sha = get_sha256(font_path)
66
  if file_exists_on_hub(font_sha, "fonts"):
67
- return gr.update(visible=False), gr.Markdown("<div style='text-align: center;'><h3>This font was already uploaded.</h3></div>"), gr.update(value=None), gr.update(value=None)
 
68
 
69
  supported_chars = get_supported_chars(font_path)
70
  if not supported_chars:
71
- return gr.update(visible=False), gr.Markdown("<div style='text-align: center;'><h3>No supported characters found in the font file.</h3></div>"), gr.update(value=None), gr.update(value=None)
 
 
72
  metadata = {
73
  "font_name": font_path.stem,
74
  "supported_characters": supported_chars,
@@ -81,21 +90,30 @@ def handle_uploads(font_upload, wordlist_upload, agree):
81
 
82
  _upload_hub(str(font_path), "fonts", font_sha)
83
  _upload_hub(str(json_path), "fonts", json_sha)
 
84
 
85
- if wordlist_upload:
86
- wordlist_path = Path(wordlist_upload)
 
87
  wordlist_sha = get_sha256(wordlist_path)
88
  if file_exists_on_hub(wordlist_sha, "wordlists"):
89
- return gr.update(visible=False), gr.Markdown("<div style='text-align: center;'><h3>This wordlist was already uploaded.</h3></div>"), gr.update(value=None), gr.update(value=None)
 
90
 
91
  _upload_hub(str(wordlist_path), "wordlists", wordlist_sha)
 
92
 
93
- return gr.update(visible=False), gr.Markdown("<div style='text-align: center;'><h3>Upload was successful! You can upload another item.</h3></div>"), gr.update(value=None), gr.update(value=None)
 
 
 
 
94
 
95
  except Exception as e:
96
  logging.exception("Upload failed")
97
  return gr.update(visible=False), gr.Markdown(f"<div style='text-align: center;'><h3>An error occurred: {e}</h3></div>"), gr.update(value=None), gr.update(value=None)
98
 
 
99
  with gr.Blocks(fill_height=True) as demo:
100
  agreement_markdown = gr.Markdown(
101
  """
@@ -130,8 +148,18 @@ with gr.Blocks(fill_height=True) as demo:
130
 
131
  with gr.Column(visible=False) as upload_section:
132
  success_message = gr.Markdown(visible=True)
133
- font_upload = gr.File(label="Upload Font File [TTF | OTF]", file_types=[".ttf", ".otf"], type="filepath")
134
- wordlist_upload = gr.File(label="Upload Wordlist [TXT]", file_types=[".txt"], type="filepath")
 
 
 
 
 
 
 
 
 
 
135
  submit_button = gr.Button("Submit")
136
 
137
  def toggle_agreement_visibility():
 
59
  if not agree:
60
  return gr.Markdown("You must agree to the terms and conditions before proceeding."), None, None, None
61
 
62
+ font_upload = font_upload or []
63
+ wordlist_upload = wordlist_upload or []
64
+
65
+ results = []
66
+
67
  try:
68
+ # Handle fonts
69
+ for font_file in font_upload:
70
+ font_path = Path(font_file)
71
  font_sha = get_sha256(font_path)
72
  if file_exists_on_hub(font_sha, "fonts"):
73
+ results.append(f"⚠️ Font **{font_path.name}** was already uploaded.")
74
+ continue
75
 
76
  supported_chars = get_supported_chars(font_path)
77
  if not supported_chars:
78
+ results.append(f"⚠️ Font **{font_path.name}** has no supported characters.")
79
+ continue
80
+
81
  metadata = {
82
  "font_name": font_path.stem,
83
  "supported_characters": supported_chars,
 
90
 
91
  _upload_hub(str(font_path), "fonts", font_sha)
92
  _upload_hub(str(json_path), "fonts", json_sha)
93
+ results.append(f"✅ Font **{font_path.name}** uploaded successfully.")
94
 
95
+ # Handle wordlists
96
+ for wordlist_file in wordlist_upload:
97
+ wordlist_path = Path(wordlist_file)
98
  wordlist_sha = get_sha256(wordlist_path)
99
  if file_exists_on_hub(wordlist_sha, "wordlists"):
100
+ results.append(f"⚠️ Wordlist **{wordlist_path.name}** was already uploaded.")
101
+ continue
102
 
103
  _upload_hub(str(wordlist_path), "wordlists", wordlist_sha)
104
+ results.append(f"✅ Wordlist **{wordlist_path.name}** uploaded successfully.")
105
 
106
+ if not results:
107
+ results.append("⚠️ No files uploaded.")
108
+
109
+ result_md = "<br>".join(results)
110
+ return gr.update(visible=False), gr.Markdown(f"<div style='text-align: center;'>{result_md}</div>"), gr.update(value=None), gr.update(value=None)
111
 
112
  except Exception as e:
113
  logging.exception("Upload failed")
114
  return gr.update(visible=False), gr.Markdown(f"<div style='text-align: center;'><h3>An error occurred: {e}</h3></div>"), gr.update(value=None), gr.update(value=None)
115
 
116
+
117
  with gr.Blocks(fill_height=True) as demo:
118
  agreement_markdown = gr.Markdown(
119
  """
 
148
 
149
  with gr.Column(visible=False) as upload_section:
150
  success_message = gr.Markdown(visible=True)
151
+ font_upload = gr.File(
152
+ label="Upload Font File(s) [TTF | OTF]",
153
+ file_types=[".ttf", ".otf"],
154
+ type="filepath",
155
+ file_count="multiple"
156
+ )
157
+ wordlist_upload = gr.File(
158
+ label="Upload Wordlist(s) [TXT]",
159
+ file_types=[".txt"],
160
+ type="filepath",
161
+ file_count="multiple"
162
+ )
163
  submit_button = gr.Button("Submit")
164
 
165
  def toggle_agreement_visibility():