elismasilva commited on
Commit
d324f3c
·
1 Parent(s): 1cb5675

fixes on handle_upload

Browse files
Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +43 -32
README.md CHANGED
@@ -29,6 +29,7 @@ app_file: app.py
29
  **An AI Agentic Tool Server for GitHub Issue Triaging & Analysis**
30
 
31
  [![MCP's 1st Birthday Hackathon](https://img.shields.io/badge/MCP%27s%201st%20Birthday-Hackathon-blue)](https://huggingface.co/MCP-1st-Birthday)
 
32
 
33
 
34
  > **🎯 Track 1 Submission**: Building MCP (Enterprise)
 
29
  **An AI Agentic Tool Server for GitHub Issue Triaging & Analysis**
30
 
31
  [![MCP's 1st Birthday Hackathon](https://img.shields.io/badge/MCP%27s%201st%20Birthday-Hackathon-blue)](https://huggingface.co/MCP-1st-Birthday)
32
+ [![Powered by Gradio](https://img.shields.io/badge/Powered%20by-Gradio-orange)](https://gradio.app/)
33
 
34
 
35
  > **🎯 Track 1 Submission**: Building MCP (Enterprise)
app.py CHANGED
@@ -1052,8 +1052,7 @@ def generate_theme(
1052
  llm_api_key (str, optional): API Key. **OPTIONAL**. If empty, uses server keys.
1053
  theme_mode (str, optional): Theme mode. Defaults to 'Designer'. Use 'Engineer' if you want to specify the details and 'Designer' if you want the model to handle that; in this mode, use short prompts.
1054
  """
1055
- global generated_theme_state
1056
-
1057
  _validate_api_keys(llm_api_key, request)
1058
 
1059
  try:
@@ -1160,8 +1159,7 @@ def generate_theme(
1160
  set_call = f".set(\n {set_args}\n)" if set_kwargs else ""
1161
  py_code = f"import gradio as gr\n\ntheme = gr.themes.Default(\n {init_args}\n){set_call}"
1162
 
1163
- generated_theme_state = theme_object
1164
- return py_code, str(status_message), css_str
1165
 
1166
  except Exception as e:
1167
  import traceback
@@ -1179,23 +1177,37 @@ def generate_theme(
1179
  raise gr.Error(detailed_msg)
1180
 
1181
 
1182
- def handle_upload(theme_name, hf_token):
1183
  """
1184
- Handles uploading the generated theme.
 
 
 
 
 
 
 
 
 
 
 
 
 
1185
  """
1186
- global generated_theme_state
1187
-
1188
- if not isinstance(generated_theme_state, gr.themes.Default):
1189
- return gr.Markdown("⚠️ Please generate a theme first.", visible=True)
1190
  if not theme_name or not hf_token:
1191
- return gr.Markdown("⚠️ Please fill in the theme name and token.", visible=True)
 
1192
  try:
1193
- url = generated_theme_state.push_to_hub(repo_name=theme_name, hf_token=hf_token, theme_name=theme_name)
1194
  space_id = "/".join(url.split("/")[-2:])
1195
- success_message = f"✅ **Success!** Theme uploaded to: [{url}]({url})\n<br>To use: `theme='{space_id}'`"
1196
- return gr.Markdown(success_message, visible=True)
1197
  except Exception as e:
1198
- return gr.Markdown(f"❌ **Error:** {e}", visible=True)
1199
 
1200
 
1201
  def _process_sketch_logic(final_image, text_description, llm_provider, llm_model, llm_api_key):
@@ -1372,7 +1384,7 @@ def _create_example_app():
1372
  "number",
1373
  "textbox",
1374
  title="Interface Component (Compact)",
1375
- # show_api=False,
1376
  api_name=False,
1377
  )
1378
  with gr.Row():
@@ -1553,7 +1565,7 @@ css = """
1553
  #app { height: 100vh; overflow-y: scroll; }
1554
  .min-h-50px { min-height: 50px; }
1555
  """
1556
- generated_theme_state = None # Setting global instead gr.State()
1557
  theme = gr.themes.Default(
1558
  primary_hue='blue',
1559
  secondary_hue='teal',
@@ -1612,7 +1624,7 @@ theme = gr.themes.Default(
1612
 
1613
  with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MCP Server)") as app:
1614
  css_data_transport = gr.Textbox(visible=False)
1615
-
1616
  gr.HTML(_get_mcp_header())
1617
 
1618
  # GLOBAL CONFIGURATION
@@ -1762,8 +1774,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1762
  with gr.TabItem("Publish to Hub"):
1763
  hub_theme_name = gr.Textbox(label="Theme Name", placeholder="my-amazing-theme")
1764
  hub_hf_token = gr.Textbox(label="HF Token", type="password", placeholder="hf_...")
1765
- upload_button = gr.Button("Upload 🚀")
1766
- upload_status = gr.Markdown(visible=False)
1767
  chatbot_comp, msg_input_comp, add_msg_btn_comp = _create_example_app()
1768
 
1769
  with gr.TabItem("BONUS 2 - Sketch Image to Gradio UI"):
@@ -1827,7 +1838,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1827
  fn=update_all_model_choices,
1828
  inputs=[global_provider],
1829
  outputs=[global_model, sketch_model_dropdown],
1830
- show_api=False,
1831
  )
1832
 
1833
  # Tool 1: Sync
@@ -1852,7 +1863,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1852
  outputs=[issue_report_output, issue_thought_output],
1853
  api_name="analyze_github_issue",
1854
  show_progress_on=[issue_report_output],
1855
- ).then(fn=change_cot_visibility, inputs=[issue_thought_output], outputs=[issue_cot_accordion], show_api=False)
1856
 
1857
  # Tool 3: Duplicate Finder
1858
  dup_find_button.click(
@@ -1872,7 +1883,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1872
  fn=change_cot_visibility,
1873
  inputs=[dup_thought_output],
1874
  outputs=[dup_accordion],
1875
- show_api=False,
1876
  )
1877
 
1878
  # Tool 4: Prioritizer
@@ -1882,7 +1893,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1882
  outputs=[prio_report_output, prio_thought_output],
1883
  api_name="prioritize_open_issues",
1884
  show_progress_on=[prio_report_output],
1885
- ).success(fn=change_cot_visibility, inputs=[prio_thought_output], outputs=[prio_cot_accordion], show_api=False)
1886
 
1887
  # Tool 5: Action Runner
1888
  action_button.click(
@@ -1933,7 +1944,7 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1933
  global_api_key,
1934
  theme_mode,
1935
  ],
1936
- outputs=[python_code_output, status_output, css_data_transport],
1937
  ).then(
1938
  fn=None,
1939
  inputs=[css_data_transport],
@@ -1942,8 +1953,8 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1942
  )
1943
  upload_button.click(
1944
  fn=handle_upload,
1945
- inputs=[hub_theme_name, hub_hf_token],
1946
- outputs=[upload_status],
1947
  )
1948
 
1949
  # Bonus 2: Sketch
@@ -1951,10 +1962,10 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1951
  fn=generate_sketch_ui,
1952
  inputs=[sketch_input, text_desc_input, global_provider, sketch_model_dropdown, global_api_key],
1953
  outputs=[sketch_code_output],
1954
- show_api=False,
1955
  )
1956
 
1957
- ui_event.success(fn=_create_gradio_lite_html, inputs=[sketch_code_output], outputs=[sketch_preview_output], show_api=False)
1958
 
1959
  api_trigger_btn.click(
1960
  fn=generate_sketch_to_ui,
@@ -1985,8 +1996,8 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1985
  fn=add_message_to_chat,
1986
  inputs=[chatbot_comp, msg_input_comp],
1987
  outputs=[chatbot_comp],
1988
- show_api=False,
1989
- ).then(fn=lambda: "", outputs=[msg_input_comp], show_api=False)
1990
 
1991
  # Init
1992
  app.load(fn=_initialize_database, inputs=None, outputs=None, show_api=False)
@@ -1994,4 +2005,4 @@ with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MC
1994
  # endregion
1995
  if __name__ == "__main__":
1996
  app.allowed_paths = ["."]
1997
- app.launch(mcp_server=True, share=True, show_error=True, server_port=7860, enable_monitoring=False)
 
1052
  llm_api_key (str, optional): API Key. **OPTIONAL**. If empty, uses server keys.
1053
  theme_mode (str, optional): Theme mode. Defaults to 'Designer'. Use 'Engineer' if you want to specify the details and 'Designer' if you want the model to handle that; in this mode, use short prompts.
1054
  """
1055
+
 
1056
  _validate_api_keys(llm_api_key, request)
1057
 
1058
  try:
 
1159
  set_call = f".set(\n {set_args}\n)" if set_kwargs else ""
1160
  py_code = f"import gradio as gr\n\ntheme = gr.themes.Default(\n {init_args}\n){set_call}"
1161
 
1162
+ return py_code, theme_object, str(status_message), css_str
 
1163
 
1164
  except Exception as e:
1165
  import traceback
 
1177
  raise gr.Error(detailed_msg)
1178
 
1179
 
1180
+ def handle_upload(theme_name, generated_theme, hf_token):
1181
  """
1182
+ Handles uploading the generated theme to Hugging Face Hub.
1183
+ This function takes a generated theme and pushes it to the Hugging Face Hub repository.
1184
+ It validates that a theme has been generated and that the required credentials are provided,
1185
+ then attempts to upload the theme and returns a success or error message.
1186
+
1187
+ Args:
1188
+ theme_name (str): The name of the theme to be uploaded. This will be used as the repository name
1189
+ on Hugging Face Hub. Must not be empty.
1190
+ generated_theme (object): Theme generated object
1191
+ hf_token (str): The Hugging Face API token for authentication. Required to push the theme to the hub.
1192
+ Must not be empty.
1193
+
1194
+ Returns
1195
+ None
1196
  """
1197
+
1198
+ if not isinstance(generated_theme, gr.themes.Default):
1199
+ gr.Info("⚠️ Please generate a theme first.")
1200
+ return
1201
  if not theme_name or not hf_token:
1202
+ gr.Info("⚠️ Please fill in the theme name and token.")
1203
+ return
1204
  try:
1205
+ url = generated_theme.push_to_hub(repo_name=theme_name, hf_token=hf_token, theme_name=theme_name)
1206
  space_id = "/".join(url.split("/")[-2:])
1207
+ gr.Info(f"✅ Success! Theme uploaded to: ({url}), To use: `theme='{space_id}'`")
1208
+ return
1209
  except Exception as e:
1210
+ raise gr.Error(f"❌ **Error:** {e}", visible=True)
1211
 
1212
 
1213
  def _process_sketch_logic(final_image, text_description, llm_provider, llm_model, llm_api_key):
 
1384
  "number",
1385
  "textbox",
1386
  title="Interface Component (Compact)",
1387
+ # api_name=False,
1388
  api_name=False,
1389
  )
1390
  with gr.Row():
 
1565
  #app { height: 100vh; overflow-y: scroll; }
1566
  .min-h-50px { min-height: 50px; }
1567
  """
1568
+
1569
  theme = gr.themes.Default(
1570
  primary_hue='blue',
1571
  secondary_hue='teal',
 
1624
 
1625
  with gr.Blocks(theme=theme, css=css, head=THEME_JS, title="GitRepo Inspector (MCP Server)") as app:
1626
  css_data_transport = gr.Textbox(visible=False)
1627
+ generated_theme_state = gr.State(value=None)
1628
  gr.HTML(_get_mcp_header())
1629
 
1630
  # GLOBAL CONFIGURATION
 
1774
  with gr.TabItem("Publish to Hub"):
1775
  hub_theme_name = gr.Textbox(label="Theme Name", placeholder="my-amazing-theme")
1776
  hub_hf_token = gr.Textbox(label="HF Token", type="password", placeholder="hf_...")
1777
+ upload_button = gr.Button("Upload 🚀")
 
1778
  chatbot_comp, msg_input_comp, add_msg_btn_comp = _create_example_app()
1779
 
1780
  with gr.TabItem("BONUS 2 - Sketch Image to Gradio UI"):
 
1838
  fn=update_all_model_choices,
1839
  inputs=[global_provider],
1840
  outputs=[global_model, sketch_model_dropdown],
1841
+ api_name=False,
1842
  )
1843
 
1844
  # Tool 1: Sync
 
1863
  outputs=[issue_report_output, issue_thought_output],
1864
  api_name="analyze_github_issue",
1865
  show_progress_on=[issue_report_output],
1866
+ ).then(fn=change_cot_visibility, inputs=[issue_thought_output], outputs=[issue_cot_accordion], api_name=False)
1867
 
1868
  # Tool 3: Duplicate Finder
1869
  dup_find_button.click(
 
1883
  fn=change_cot_visibility,
1884
  inputs=[dup_thought_output],
1885
  outputs=[dup_accordion],
1886
+ api_name=False,
1887
  )
1888
 
1889
  # Tool 4: Prioritizer
 
1893
  outputs=[prio_report_output, prio_thought_output],
1894
  api_name="prioritize_open_issues",
1895
  show_progress_on=[prio_report_output],
1896
+ ).success(fn=change_cot_visibility, inputs=[prio_thought_output], outputs=[prio_cot_accordion], api_name=False)
1897
 
1898
  # Tool 5: Action Runner
1899
  action_button.click(
 
1944
  global_api_key,
1945
  theme_mode,
1946
  ],
1947
+ outputs=[python_code_output, generated_theme_state, status_output, css_data_transport],
1948
  ).then(
1949
  fn=None,
1950
  inputs=[css_data_transport],
 
1953
  )
1954
  upload_button.click(
1955
  fn=handle_upload,
1956
+ inputs=[hub_theme_name, generated_theme_state, hub_hf_token],
1957
+ api_name=False
1958
  )
1959
 
1960
  # Bonus 2: Sketch
 
1962
  fn=generate_sketch_ui,
1963
  inputs=[sketch_input, text_desc_input, global_provider, sketch_model_dropdown, global_api_key],
1964
  outputs=[sketch_code_output],
1965
+ api_name=False,
1966
  )
1967
 
1968
+ ui_event.success(fn=_create_gradio_lite_html, inputs=[sketch_code_output], outputs=[sketch_preview_output], api_name=False)
1969
 
1970
  api_trigger_btn.click(
1971
  fn=generate_sketch_to_ui,
 
1996
  fn=add_message_to_chat,
1997
  inputs=[chatbot_comp, msg_input_comp],
1998
  outputs=[chatbot_comp],
1999
+ api_name=False,
2000
+ ).then(fn=lambda: "", outputs=[msg_input_comp], api_name=False)
2001
 
2002
  # Init
2003
  app.load(fn=_initialize_database, inputs=None, outputs=None, show_api=False)
 
2005
  # endregion
2006
  if __name__ == "__main__":
2007
  app.allowed_paths = ["."]
2008
+ app.launch(mcp_server=True, share=True, show_error=True, server_port=7860)