sanaweb commited on
Commit
5b94dcd
·
verified ·
1 Parent(s): 8fc7ce7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,26 +1,22 @@
1
- import requests
2
- from google.cloud import storage
3
 
4
- def upload_file_to_gcs(file_url, bucket_name, object_name):
5
  # Download the file from the URL
6
  response = requests.get(file_url)
7
  file_content = response.content
8
 
9
- # Initialize the Google Cloud Storage client
10
- storage_client = storage.Client()
 
11
 
12
- # Get the bucket
13
- bucket = storage_client.bucket(bucket_name)
14
 
15
- # Create a new blob and upload the file content
16
- blob = bucket.blob(object_name)
17
- blob.upload_from_string(file_content)
18
 
19
- print(f"File uploaded to {bucket_name}/{object_name}")
20
-
21
- # Replace 'your-bucket-name' and 'your-file-name.ext' with your actual bucket name and desired object name
22
- bucket_name = 'your-bucket-name'
23
  file_url = 'https://dkstatics-public.digikala.com/digikala-products/26c6255b595c4aac4c30f7fa6644c1a726b70972_1694005299.jpg'
24
- object_name = '1694005299.jpg'
25
 
26
- upload_file_to_gcs(file_url, bucket_name, object_name)
 
1
+ from transformers import HfApi
 
2
 
3
+ def upload_file_to_huggingface(file_url, filename, api_token):
4
  # Download the file from the URL
5
  response = requests.get(file_url)
6
  file_content = response.content
7
 
8
+ # Initialize the Hugging Face API client
9
+ hf_api = HfApi()
10
+ hf_api.set_access_token(api_token)
11
 
12
+ # Upload the file to Hugging Face
13
+ hf_api.upload_file(filename, file_content)
14
 
15
+ print(f"File uploaded to Hugging Face as {filename}")
 
 
16
 
17
+ # Replace 'your-api-token' with your actual Hugging Face API token
18
+ api_token = '26c6255b595c4aac4c30f7fa6644c1a726b70972_1694005299.jpg'
 
 
19
  file_url = 'https://dkstatics-public.digikala.com/digikala-products/26c6255b595c4aac4c30f7fa6644c1a726b70972_1694005299.jpg'
20
+ filename = '26c6255b595c4aac4c30f7fa6644c1a726b70972_1694005299.jpg'
21
 
22
+ upload_file_to_huggingface(file_url, filename, api_token)