reach-vb HF staff commited on
Commit
d25d1b2
1 Parent(s): be16bab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -32,7 +32,7 @@ def fetch_manifest(image, tag):
32
 
33
  def upload_to_huggingface(repo_id, folder_path):
34
  api = HfApi(token=HF_TOKEN)
35
- repo_path = api.create_repo(repo_id, "model", exist_ok=True,)
36
  print(f"Repo created {repo_path}")
37
  try:
38
  api.upload_folder(
@@ -73,28 +73,28 @@ def process_image_tag(image_tag, repo_id):
73
  download_file(config_digest, image)
74
 
75
  # Upload to Hugging Face Hub
76
- upload_result = upload_to_huggingface(repo_id, 'blobs/*')
77
 
78
  # Delete the blobs folder
79
-
80
  os.rmtree('blobs')
81
  return f"Successfully fetched and downloaded files for {image}:{tag}\n{upload_result}\nBlobs folder deleted"
82
  except Exception as e:
83
- os.rmtree('blobs')
84
  return f"Error found: {str(e)}"
85
 
86
- # Create the Gradio interface
87
- iface = gr.Interface(
88
- fn=process_image_tag,
89
- inputs=[
90
- gr.Textbox(placeholder="Enter Ollama ID", label="Image and Tag"),
91
- gr.Textbox(placeholder="Enter Hugging Face repo ID", label="Hugging Face Repo ID"),
92
- )
93
- ],
94
- outputs=gr.Textbox(label="Result"),
95
- title="Ollama <> HF Hub 🤝",
96
- description="Enter the image and tag to download the corresponding files from the Ollama registry and upload them to the Hugging Face Hub."
97
- )
 
98
 
99
  # Launch the Gradio app
100
- iface.launch()
 
32
 
33
  def upload_to_huggingface(repo_id, folder_path):
34
  api = HfApi(token=HF_TOKEN)
35
+ repo_path = api.create_repo(repo_id, "model", exist_ok=True)
36
  print(f"Repo created {repo_path}")
37
  try:
38
  api.upload_folder(
 
73
  download_file(config_digest, image)
74
 
75
  # Upload to Hugging Face Hub
76
+ upload_result = upload_to_huggingface(repo_id, 'blobs')
77
 
78
  # Delete the blobs folder
 
79
  os.rmtree('blobs')
80
  return f"Successfully fetched and downloaded files for {image}:{tag}\n{upload_result}\nBlobs folder deleted"
81
  except Exception as e:
82
+ os.rmtree('blobs', ignore_errors=True)
83
  return f"Error found: {str(e)}"
84
 
85
+ # Create the Gradio interface using gr.Blocks
86
+ with gr.Blocks() as demo:
87
+ gr.Markdown("# Ollama <> HF Hub 🤝")
88
+ gr.Markdown("Enter the image and tag to download the corresponding files from the Ollama registry and upload them to the Hugging Face Hub.")
89
+
90
+ with gr.Row():
91
+ image_tag_input = gr.Textbox(placeholder="Enter Ollama ID", label="Image and Tag")
92
+ repo_id_input = gr.Textbox(placeholder="Enter Hugging Face repo ID", label="Hugging Face Repo ID")
93
+
94
+ result_output = gr.Textbox(label="Result")
95
+
96
+ process_button = gr.Button("Process")
97
+ process_button.click(fn=process_image_tag, inputs=[image_tag_input, repo_id_input], outputs=result_output)
98
 
99
  # Launch the Gradio app
100
+ demo.launch()