Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,12 +16,20 @@ import string
|
|
16 |
import random
|
17 |
from g4f.client import Client
|
18 |
|
|
|
|
|
|
|
19 |
client = Client()
|
20 |
|
21 |
|
22 |
|
23 |
app = Flask(__name__)
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
limiter = Limiter(
|
26 |
app,
|
27 |
default_limits=["30 per minute"]
|
@@ -383,6 +391,35 @@ def handle_message():
|
|
383 |
except Exception as e:
|
384 |
return jsonify({"error": str(e)}), 500
|
385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
|
387 |
if __name__ == "__main__":
|
388 |
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
16 |
import random
|
17 |
from g4f.client import Client
|
18 |
|
19 |
+
import tempfile
|
20 |
+
from huggingface_hub import HfApi, login
|
21 |
+
|
22 |
client = Client()
|
23 |
|
24 |
|
25 |
|
26 |
app = Flask(__name__)
|
27 |
|
28 |
+
HF_TOKEN = os.environ.get('HF_TOKEN')
|
29 |
+
login(token=HF_TOKEN)
|
30 |
+
|
31 |
+
api = HfApi()
|
32 |
+
|
33 |
limiter = Limiter(
|
34 |
app,
|
35 |
default_limits=["30 per minute"]
|
|
|
391 |
except Exception as e:
|
392 |
return jsonify({"error": str(e)}), 500
|
393 |
|
394 |
+
|
395 |
+
@app.route('/make-text', methods=['GET'])
|
396 |
+
def make_text():
|
397 |
+
query = request.args.get('query')
|
398 |
+
file_name = request.args.get('fileName')
|
399 |
+
|
400 |
+
if not query or not file_name:
|
401 |
+
return "Both 'query' and 'fileName' parameters are required", 400
|
402 |
+
|
403 |
+
# Create a temporary file
|
404 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
405 |
+
temp_file.write(query)
|
406 |
+
temp_file_path = temp_file.name
|
407 |
+
|
408 |
+
try:
|
409 |
+
# Upload the temporary file to Hugging Face
|
410 |
+
api.upload_file(
|
411 |
+
path_or_fileobj=temp_file_path,
|
412 |
+
path_in_repo=file_name,
|
413 |
+
repo_id="thunder-lord/test-1",
|
414 |
+
repo_type="dataset",
|
415 |
+
)
|
416 |
+
return f"File '{file_name}' uploaded successfully", 200
|
417 |
+
except Exception as e:
|
418 |
+
return f"Error uploading file: {str(e)}", 500
|
419 |
+
finally:
|
420 |
+
# Clean up the temporary file
|
421 |
+
os.unlink(temp_file_path)
|
422 |
+
|
423 |
|
424 |
if __name__ == "__main__":
|
425 |
app.run(host="0.0.0.0", port=7860, debug=True)
|