Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,22 @@
|
|
1 |
-
import
|
2 |
-
from google.cloud import storage
|
3 |
|
4 |
-
def
|
5 |
# Download the file from the URL
|
6 |
response = requests.get(file_url)
|
7 |
file_content = response.content
|
8 |
|
9 |
-
# Initialize the
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
blob = bucket.blob(object_name)
|
17 |
-
blob.upload_from_string(file_content)
|
18 |
|
19 |
-
|
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 |
-
|
25 |
|
26 |
-
|
|
|
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)
|