File size: 1,435 Bytes
209a278
e1fc40e
 
 
 
209a278
 
6a07040
5e6ce82
6a07040
 
 
 
 
 
 
 
 
 
 
2c68506
6a07040
 
 
 
 
 
 
 
 
 
 
 
 
 
783f9ad
6a07040
 
 
 
 
 
209a278
6a07040
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
from io import BytesIO
from flask import Flask, request, jsonify
from gradio_client import Client
from huggingface_hub import create_repo, upload_file

app = Flask(__name__)

@app.route('/upload_model', methods=['POST'])
def upload_model():
    # Par芒metros
    file_name= request.args.get('file_name', default='')
    repo = request.args.get('repo', default='')
    url = request.args.get('url', default='')
    token = request.args.get('token', default='')

    try:
        # Crie o reposit贸rio
        repo_id = repo
        create_repo(repo_id=repo_id, token=token)

        # Fa莽a o download do conte煤do da URL em mem贸ria
        response = requests.get(url)
        if response.status_code == 200:
            # Obtenha o conte煤do do arquivo em bytes
            file_content = response.content
            # Crie um objeto de arquivo em mem贸ria
            file_obj = BytesIO(file_content)
            # Fa莽a o upload do arquivo
            upload_file(
                path_or_fileobj=file_obj,
                path_in_repo=file_name,
                repo_id=repo_id,
                token=token
            )

            # Mensagem de sucesso
            return jsonify({"message": "Sucess"})
        else:
            return jsonify({"error": "Failed"}), 500
    except Exception as e:
        return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)