Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,17 @@
|
|
1 |
import requests
|
2 |
-
import
|
3 |
|
|
|
|
|
|
|
4 |
def get_waifu_image():
|
5 |
try:
|
6 |
response = requests.get('https://api.waifu.pics/sfw/waifu')
|
7 |
response.raise_for_status() # Memastikan permintaan berhasil
|
8 |
image_url = response.json().get('url') # Mengambil URL gambar
|
9 |
-
return {"url": image_url} # Mengembalikan hasil dalam format JSON
|
10 |
except Exception as e:
|
11 |
-
return {"error": str(e)}
|
12 |
-
|
13 |
-
# Membuat interface Gradio
|
14 |
-
iface = gr.Interface(
|
15 |
-
fn=get_waifu_image,
|
16 |
-
inputs=[],
|
17 |
-
outputs="json", # Mengatur output ke format JSON
|
18 |
-
title="Waifu Image Fetcher",
|
19 |
-
description="Mengambil gambar Waifu dan menampilkan URL dalam format JSON."
|
20 |
-
)
|
21 |
|
22 |
-
# Menjalankan aplikasi
|
23 |
if __name__ == "__main__":
|
24 |
-
|
|
|
1 |
import requests
|
2 |
+
from flask import Flask, jsonify
|
3 |
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
@app.route('/get_waifu_image', methods=['GET'])
|
7 |
def get_waifu_image():
|
8 |
try:
|
9 |
response = requests.get('https://api.waifu.pics/sfw/waifu')
|
10 |
response.raise_for_status() # Memastikan permintaan berhasil
|
11 |
image_url = response.json().get('url') # Mengambil URL gambar
|
12 |
+
return jsonify({"url": image_url}) # Mengembalikan hasil dalam format JSON
|
13 |
except Exception as e:
|
14 |
+
return jsonify({"error": str(e)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
16 |
if __name__ == "__main__":
|
17 |
+
app.run(host='0.0.0.0', port=7860)
|