Spaces:
Sleeping
Sleeping
khaledeng15
commited on
Commit
β’
1f01f64
1
Parent(s):
34a97e0
Add multiPages
Browse files- CMD.md +1 -0
- __pycache__/app.cpython-312.pyc +0 -0
- __pycache__/blip_image_captioning.cpython-312.pyc +0 -0
- __pycache__/home.cpython-312.pyc +0 -0
- app.py +86 -10
- home.py +55 -0
- webpages/__pycache__/blip_image_captioning.cpython-312.pyc +0 -0
- webpages/blip_image_captioning.py +37 -0
CMD.md
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio app.py
|
__pycache__/app.cpython-312.pyc
ADDED
Binary file (3.27 kB). View file
|
|
__pycache__/blip_image_captioning.cpython-312.pyc
ADDED
Binary file (691 Bytes). View file
|
|
__pycache__/home.cpython-312.pyc
ADDED
Binary file (2.32 kB). View file
|
|
app.py
CHANGED
@@ -1,16 +1,92 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
-
def launch(input):
|
9 |
-
out = pipe(input)
|
10 |
-
return out[0]['generated_text']
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# DEV reloads require a refresh on the browser.
|
2 |
+
# https://gist.github.com/brandon8863/3ee552870a066eba463d37f0b39a547a
|
3 |
import gradio as gr
|
4 |
+
import webpages.blip_image_captioning as blip_image_captioning
|
5 |
+
import home as home
|
6 |
|
7 |
+
|
8 |
+
def routs():
|
9 |
+
with gr.Column():
|
10 |
+
# anchor = gr.HTML("<h1>π </h1>")
|
11 |
+
anchor = gr.HTML("<br/><br/><br/><br/>")
|
12 |
+
#
|
13 |
+
# BUTTONS FOR PAGE NAVIGATION
|
14 |
+
#
|
15 |
+
with gr.Column() as result:
|
16 |
+
gr.Button("π Home", link="/?page=home")
|
17 |
+
gr.Button("π Find out what in the photo", link="/?page=blip_image_captioning")
|
18 |
+
|
19 |
+
def handePages(local_state):
|
20 |
+
with gr.Column(scale=30):
|
21 |
+
#
|
22 |
+
# SIMPLE PAGE ROUTING HERE
|
23 |
+
#
|
24 |
+
if (
|
25 |
+
local_state == None
|
26 |
+
):
|
27 |
+
return home.get_landing_page(local_state), local_state
|
28 |
+
elif local_state == "home":
|
29 |
+
return home.get(), local_state
|
30 |
+
elif local_state == "blip_image_captioning":
|
31 |
+
return blip_image_captioning.get(local_state), local_state
|
32 |
+
else:
|
33 |
+
return (
|
34 |
+
home.get_not_found_page(local_state),
|
35 |
+
local_state,
|
36 |
+
)
|
37 |
|
38 |
|
|
|
|
|
|
|
39 |
|
40 |
+
# =======================================================================================================
|
41 |
+
# APP_SHELL - for multiple pages
|
42 |
+
#
|
43 |
+
with gr.Blocks(fill_height=True , css=".contain { display: flex !important; flex-direction: column !important; }"
|
44 |
+
"#component-0, #component-3, #component-10, #component-8 { height: 100% !important; }"
|
45 |
+
"#chatbot { flex-grow: 1 !important; overflow: auto !important;}"
|
46 |
+
"#col { height: calc(100vh - 112px - 16px) !important; }") as demo:
|
47 |
|
48 |
+
def init_state(request: gr.Request):
|
49 |
+
#
|
50 |
+
# PULL URL PARAMS HERE
|
51 |
+
#
|
52 |
+
page = request.query_params.get("page")
|
53 |
+
print(f"** page: {page}")
|
54 |
+
if (
|
55 |
+
page == None
|
56 |
+
):
|
57 |
+
page = "home"
|
58 |
+
# result["page"] = request.query_params.get("page")
|
59 |
+
return page # this result populates "state"
|
60 |
+
|
61 |
+
state = gr.State()
|
62 |
+
|
63 |
+
#
|
64 |
+
# POPULATE user "state" with request data
|
65 |
+
#
|
66 |
+
demo.load(
|
67 |
+
fn=init_state,
|
68 |
+
inputs=None,
|
69 |
+
outputs=state,
|
70 |
+
queue=True,
|
71 |
+
show_progress=False,
|
72 |
+
)
|
73 |
+
|
74 |
+
content = gr.HTML("...")
|
75 |
+
|
76 |
+
@gr.render(inputs=[state], triggers=[state.change])
|
77 |
+
def page_content(local_state):
|
78 |
+
print(f"** local_state: {local_state}")
|
79 |
+
with gr.Row(variant="panel") as result:
|
80 |
+
routs()
|
81 |
+
handePages(local_state)
|
82 |
+
|
83 |
+
#
|
84 |
+
# HACK: Would be nice to delay rendering until state is populated
|
85 |
+
#
|
86 |
+
def page_content_update(local_state):
|
87 |
+
return gr.HTML("...",visible=False )
|
88 |
+
|
89 |
+
state.change(fn=page_content_update, inputs=state, outputs=content)
|
90 |
+
|
91 |
+
|
92 |
+
demo.launch()
|
home.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
def get() :
|
6 |
+
with gr.Column() as result:
|
7 |
+
gr.HTML("<br/><br/><br/><br/>")
|
8 |
+
gr.Markdown("# Welcome to Khaled Space! π",height=100)
|
9 |
+
|
10 |
+
gr.Markdown( """
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
Welcome to **Khaled's AI Learning Hub**! π
|
15 |
+
|
16 |
+
This platform is dedicated to showcasing AI development projects, all designed to help you explore and understand the power of artificial intelligence. π€π‘
|
17 |
+
|
18 |
+
**π Select a project from the sidebar** to see hands-on examples ranging from data processing to model deployment. Each project page will guide you through different aspects of AI development, helping you gain practical insights.
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
""")
|
25 |
+
gr.HTML("<br/><br/><br/><br/>")
|
26 |
+
|
27 |
+
|
28 |
+
return result
|
29 |
+
|
30 |
+
|
31 |
+
#
|
32 |
+
# PAGES can be in external files
|
33 |
+
#
|
34 |
+
def get_not_found_page(local_state):
|
35 |
+
with gr.Column() as result:
|
36 |
+
gr.Markdown("## 404 - PAGE NOT FOUND")
|
37 |
+
|
38 |
+
gr.Label(f"404 Page {type(local_state)}: {local_state }")
|
39 |
+
return result
|
40 |
+
|
41 |
+
|
42 |
+
def get_landing_page(local_state):
|
43 |
+
with gr.Column() as result:
|
44 |
+
gr.Markdown("## LANDING PAGE")
|
45 |
+
|
46 |
+
if local_state:
|
47 |
+
gr.Label(f"Landing Page {type(local_state)}")
|
48 |
+
gr.Label(f"Page: {local_state }")
|
49 |
+
return result
|
50 |
+
|
51 |
+
|
52 |
+
# with gr.Blocks() as demo:
|
53 |
+
# get()
|
54 |
+
# if __name__ == "__main__":
|
55 |
+
# demo.launch()
|
webpages/__pycache__/blip_image_captioning.cpython-312.pyc
ADDED
Binary file (1.34 kB). View file
|
|
webpages/blip_image_captioning.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# class blip_image_captioning:
|
5 |
+
# def __init__(self):
|
6 |
+
|
7 |
+
pipe = pipeline("image-to-text",
|
8 |
+
model="Salesforce/blip-image-captioning-base")
|
9 |
+
|
10 |
+
|
11 |
+
def launch(input):
|
12 |
+
out = pipe(input)
|
13 |
+
return out[0]['generated_text']
|
14 |
+
|
15 |
+
def itf():
|
16 |
+
return gr.Interface(launch,
|
17 |
+
inputs=gr.Image(type='pil'),
|
18 |
+
outputs="text")
|
19 |
+
|
20 |
+
iface = gr.Interface(launch,
|
21 |
+
inputs=gr.Image(type='pil'),
|
22 |
+
outputs="text")
|
23 |
+
# def __str__(self):
|
24 |
+
# return gr.Interface(launch,
|
25 |
+
# inputs=gr.Image(type='pil'),
|
26 |
+
# outputs="text")
|
27 |
+
|
28 |
+
# iface.launch()
|
29 |
+
|
30 |
+
def get(local_state):
|
31 |
+
with gr.Column() as result:
|
32 |
+
gr.HTML("<br/>")
|
33 |
+
gr.Markdown("## Find out what in the photo")
|
34 |
+
itf()
|
35 |
+
gr.HTML("<br/><br/><br/><br/>")
|
36 |
+
|
37 |
+
return result
|