badaoui HF Staff commited on
Commit
7d762a5
·
verified ·
1 Parent(s): 3e43106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -24
app.py CHANGED
@@ -23,13 +23,14 @@ repo: Optional[Repository] = None
23
  # if HF_TOKEN:
24
  # repo = Repository(local_dir=DATADIR, clone_from=DATASET_REPO_URL, token=HF_TOKEN)
25
 
 
26
  def neuron_export(model_id: str, task: str) -> str:
27
  if not model_id:
28
  return f"### Invalid input 🐞 Please specify a model name, got {model_id}"
29
 
30
  try:
31
- api = HfApi(token=HF_TOKEN)
32
- token = HF_TOKEN
33
 
34
  error, commit_info = convert(api=api, model_id=model_id, task=task, token=token)
35
  if error != "0":
@@ -60,24 +61,6 @@ def neuron_export(model_id: str, task: str) -> str:
60
  except Exception as e:
61
  return f"#### Error: {e}"
62
 
63
- # --- Custom CSS for dark/light mode fix ---
64
- CUSTOM_CSS = """
65
- <style>
66
- /* Default light mode style */
67
- input.hub-search-input {
68
- color: black !important;
69
- background-color: white !important;
70
- }
71
-
72
- /* Dark mode overrides */
73
- @media (prefers-color-scheme: dark) {
74
- input.hub-search-input {
75
- color: white !important;
76
- background-color: #1f1f1f !important;
77
- }
78
- }
79
- </style>
80
- """
81
 
82
  TITLE_IMAGE = """
83
  <div style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
@@ -103,8 +86,63 @@ Export 🤗 Transformers models hosted on the Hugging Face Hub to AWS Neuron-opt
103
  - PR creation requires the Space owner to have a valid write token set via HF_WRITE_TOKEN
104
  """
105
 
106
- with gr.Blocks() as demo:
107
- gr.HTML(CUSTOM_CSS)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  gr.HTML(TITLE_IMAGE)
109
  gr.HTML(TITLE)
110
 
@@ -117,7 +155,6 @@ with gr.Blocks() as demo:
117
  label="Hub model ID",
118
  placeholder="Search for model ID on the hub",
119
  search_type="model",
120
- elem_classes=["hub-search-input"]
121
  )
122
  input_task = gr.Textbox(
123
  value="auto",
@@ -133,6 +170,7 @@ with gr.Blocks() as demo:
133
  outputs=output,
134
  )
135
 
 
136
  if __name__ == "__main__":
137
  def restart_space():
138
  if HF_TOKEN:
@@ -142,4 +180,4 @@ if __name__ == "__main__":
142
  scheduler.add_job(restart_space, "interval", seconds=21600)
143
  scheduler.start()
144
 
145
- demo.launch()
 
23
  # if HF_TOKEN:
24
  # repo = Repository(local_dir=DATADIR, clone_from=DATASET_REPO_URL, token=HF_TOKEN)
25
 
26
+
27
  def neuron_export(model_id: str, task: str) -> str:
28
  if not model_id:
29
  return f"### Invalid input 🐞 Please specify a model name, got {model_id}"
30
 
31
  try:
32
+ api = HfApi(token=HF_TOKEN) # Use HF_TOKEN if available, else anonymous
33
+ token = HF_TOKEN # Pass token to convert only if available
34
 
35
  error, commit_info = convert(api=api, model_id=model_id, task=task, token=token)
36
  if error != "0":
 
61
  except Exception as e:
62
  return f"#### Error: {e}"
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  TITLE_IMAGE = """
66
  <div style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
 
86
  - PR creation requires the Space owner to have a valid write token set via HF_WRITE_TOKEN
87
  """
88
 
89
+ # Custom CSS to fix dark mode compatibility and transparency issues
90
+ CUSTOM_CSS = """
91
+ /* Fix for HuggingfaceHubSearch component visibility in both light and dark modes */
92
+ .gradio-container .gr-form {
93
+ background: var(--background-fill-primary) !important;
94
+ border: 1px solid var(--border-color-primary) !important;
95
+ }
96
+
97
+ /* Ensure text is visible in both modes */
98
+ .gradio-container input[type="text"],
99
+ .gradio-container textarea,
100
+ .gradio-container .gr-textbox input {
101
+ color: var(--body-text-color) !important;
102
+ background: var(--input-background-fill) !important;
103
+ border: 1px solid var(--border-color-primary) !important;
104
+ }
105
+
106
+ /* Fix dropdown/search results visibility */
107
+ .gradio-container .gr-dropdown,
108
+ .gradio-container .gr-dropdown .gr-box,
109
+ .gradio-container [data-testid="textbox"] {
110
+ background: var(--background-fill-primary) !important;
111
+ color: var(--body-text-color) !important;
112
+ border: 1px solid var(--border-color-primary) !important;
113
+ }
114
+
115
+ /* Fix for search component specifically */
116
+ .gradio-container .gr-form > div,
117
+ .gradio-container .gr-form input {
118
+ background: var(--input-background-fill) !important;
119
+ color: var(--body-text-color) !important;
120
+ }
121
+
122
+ /* Ensure proper contrast for placeholder text */
123
+ .gradio-container input::placeholder {
124
+ color: var(--body-text-color-subdued) !important;
125
+ opacity: 0.7;
126
+ }
127
+
128
+ /* Fix any remaining transparent backgrounds */
129
+ .gradio-container .gr-box,
130
+ .gradio-container .gr-panel {
131
+ background: var(--background-fill-primary) !important;
132
+ }
133
+
134
+ /* Make sure search results are visible */
135
+ .gradio-container .gr-dropdown-item {
136
+ color: var(--body-text-color) !important;
137
+ background: var(--background-fill-primary) !important;
138
+ }
139
+
140
+ .gradio-container .gr-dropdown-item:hover {
141
+ background: var(--background-fill-secondary) !important;
142
+ }
143
+ """
144
+
145
+ with gr.Blocks(css=CUSTOM_CSS) as demo:
146
  gr.HTML(TITLE_IMAGE)
147
  gr.HTML(TITLE)
148
 
 
155
  label="Hub model ID",
156
  placeholder="Search for model ID on the hub",
157
  search_type="model",
 
158
  )
159
  input_task = gr.Textbox(
160
  value="auto",
 
170
  outputs=output,
171
  )
172
 
173
+
174
  if __name__ == "__main__":
175
  def restart_space():
176
  if HF_TOKEN:
 
180
  scheduler.add_job(restart_space, "interval", seconds=21600)
181
  scheduler.start()
182
 
183
+ demo.launch()