Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
KOYEB_API = "https://downloadmovieab.koyeb.app"
|
| 6 |
+
|
| 7 |
+
def fetch_root():
|
| 8 |
+
res = requests.get(KOYEB_API)
|
| 9 |
+
return res.text
|
| 10 |
+
|
| 11 |
+
def search_movie(query):
|
| 12 |
+
url = f"{KOYEB_API}/api/search/{query}"
|
| 13 |
+
res = requests.get(url, headers={"Accept": "application/json"})
|
| 14 |
+
return res.json()
|
| 15 |
+
|
| 16 |
+
def trending_movies():
|
| 17 |
+
url = f"{KOYEB_API}/api/trending"
|
| 18 |
+
res = requests.get(url)
|
| 19 |
+
return res.json()
|
| 20 |
+
|
| 21 |
+
def movie_info(movie_id):
|
| 22 |
+
url = f"{KOYEB_API}/api/info/{movie_id}"
|
| 23 |
+
res = requests.get(url)
|
| 24 |
+
return res.json()
|
| 25 |
+
|
| 26 |
+
# Gradio interface
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("## Movie API Proxy via Gradio")
|
| 29 |
+
|
| 30 |
+
with gr.Tab("Root"):
|
| 31 |
+
gr.Button("Fetch Root").click(fetch_root, outputs=gr.Textbox())
|
| 32 |
+
|
| 33 |
+
with gr.Tab("Search"):
|
| 34 |
+
query_input = gr.Textbox(label="Search Query")
|
| 35 |
+
search_btn = gr.Button("Search")
|
| 36 |
+
search_btn.click(search_movie, inputs=query_input, outputs=gr.JSON())
|
| 37 |
+
|
| 38 |
+
with gr.Tab("Trending"):
|
| 39 |
+
gr.Button("Trending Movies").click(trending_movies, outputs=gr.JSON())
|
| 40 |
+
|
| 41 |
+
with gr.Tab("Movie Info"):
|
| 42 |
+
movie_id_input = gr.Textbox(label="Movie ID")
|
| 43 |
+
info_btn = gr.Button("Get Info")
|
| 44 |
+
info_btn.click(movie_info, inputs=movie_id_input, outputs=gr.JSON())
|
| 45 |
+
|
| 46 |
+
demo.launch()
|