Update app.py
Browse files
app.py
CHANGED
@@ -86,87 +86,9 @@ with gr.Blocks(theme='pikto/theme@>=0.0.1,<0.0.3') as pan:
|
|
86 |
|
87 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2,])
|
88 |
|
89 |
-
with gr.Tab("Flip Image"):
|
90 |
#Using Gradio Demos as API - This is Hot!
|
91 |
-
|
92 |
-
API_URL_NEXT10 = "https://ysharma-playground-ai-exploration.hf.space/run/next_10_rows"
|
93 |
-
|
94 |
-
#define inference function
|
95 |
-
#First: Get initial images for the grid display
|
96 |
-
def get_initial_images():
|
97 |
-
response = requests.post(API_URL_INITIAL, json={
|
98 |
-
"data": []
|
99 |
-
}).json()
|
100 |
-
#data = response["data"][0]['data'][0][0][:-1]
|
101 |
-
response_dict = response['data'][0]
|
102 |
-
return response_dict #, [resp[0][:-1] for resp in response["data"][0]["data"]]
|
103 |
-
|
104 |
-
#Second: Process response dictionary to get imges as hyperlinked image tags
|
105 |
-
def process_response(response_dict):
|
106 |
-
return [resp[0][:-1] for resp in response_dict["data"]]
|
107 |
-
|
108 |
-
response_dict = get_initial_images()
|
109 |
-
initial = process_response(response_dict)
|
110 |
-
initial_imgs = '<div style="display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); grid-gap: 0; background-color: #fff; padding: 20px; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);">\n' + "\n".join(initial[:-1])
|
111 |
-
|
112 |
-
#Third: Load more images for the grid
|
113 |
-
def get_next10_images(response_dict, row_count):
|
114 |
-
row_count = int(row_count)
|
115 |
-
#print("(1)",type(response_dict))
|
116 |
-
#Convert the string to a dictionary
|
117 |
-
if isinstance(response_dict, dict) == False :
|
118 |
-
response_dict = ast.literal_eval(response_dict)
|
119 |
-
response = requests.post(API_URL_NEXT10, json={
|
120 |
-
"data": [response_dict, row_count ] #len(initial)-1
|
121 |
-
}).json()
|
122 |
-
row_count+=10
|
123 |
-
response_dict = response['data'][0]
|
124 |
-
#print("(2)",type(response))
|
125 |
-
#print("(3)",type(response['data'][0]))
|
126 |
-
next_set = [resp[0][:-1] for resp in response_dict["data"]]
|
127 |
-
next_set_images = '<div style="display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); grid-gap: 0; background-color: #fff; padding: 20px; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); ">\n' + "\n".join(next_set[:-1])
|
128 |
-
return response_dict, row_count, next_set_images #response['data'][0]
|
129 |
-
|
130 |
-
#get_next10_images(response_dict=response_dict, row_count=9)
|
131 |
-
#position: fixed; top: 0; left: 0; width: 100%; background-color: #fff; padding: 20px; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
132 |
-
|
133 |
-
#Defining the Blocks layout
|
134 |
-
with gr.Blocks(css = """#img_search img {width: 100%; height: 100%; object-fit: cover;}""") as demo:
|
135 |
-
gr.HTML(value="top of page", elem_id="top",visible=False)
|
136 |
-
gr.HTML("""<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
137 |
-
<div
|
138 |
-
style="
|
139 |
-
display: inline-flex;
|
140 |
-
align-items: center;
|
141 |
-
gap: 0.8rem;
|
142 |
-
font-size: 1.75rem;
|
143 |
-
"
|
144 |
-
>
|
145 |
-
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
|
146 |
-
Using Gradio Demos as API - 2 </h1><br></div>
|
147 |
-
<div><h4 style="font-weight: 500; margin-bottom: 7px; margin-top: 5px;">
|
148 |
-
Stream <a href="https://github.com/playgroundai/liked_images" target="_blank">PlaygroundAI Images</a> ina beautiful grid</h4><br>
|
149 |
-
</div>""")
|
150 |
-
with gr.Accordion(label="Details about the working:", open=False, elem_id='accordion'):
|
151 |
-
gr.HTML("""
|
152 |
-
<p style="margin-bottom: 10px; font-size: 90%"><br>
|
153 |
-
▶️Do you see the "view api" link located in the footer of this application?
|
154 |
-
By clicking on this link, a page will open which provides documentation on the REST API that developers can use to query the Interface function / Block events.<br>
|
155 |
-
▶️In this demo, I am making such an API request to the <a href="https://huggingface.co/spaces/ysharma/Playground_AI_Exploration" target="_blank">Playground_AI_Exploration</a> Space.<br>
|
156 |
-
▶️I am exposing an API endpoint of this Gradio app as well. This can easily be done by one line of code, just set the api_name parameter of the event listener.
|
157 |
-
</p></div>""")
|
158 |
-
|
159 |
-
with gr.Column(): #(elem_id = "col-container"):
|
160 |
-
b1 = gr.Button("Load More Images").style(full_width=False)
|
161 |
-
df = gr.Textbox(visible=False,elem_id='dataframe', value=response_dict)
|
162 |
-
row_count = gr.Number(visible=False, value=19 )
|
163 |
-
img_search = gr.HTML(label = 'Images from PlaygroundAI dataset', elem_id="img_search",
|
164 |
-
value=initial_imgs ) #initial[:-1] )
|
165 |
-
|
166 |
-
gr.HTML('''<center><a href="https://huggingface.co/spaces/ysharma/Stream_PlaygroundAI_Images?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></center>
|
167 |
-
</p></div>''')
|
168 |
-
b1.click(get_next10_images, [df, row_count], [df, row_count, img_search], api_name = "load_playgroundai_images" )
|
169 |
-
|
170 |
|
171 |
with gr.Tab("Diffuser"):
|
172 |
with gr.Row():
|
|
|
86 |
|
87 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2,])
|
88 |
|
89 |
+
#with gr.Tab("Flip Image"):
|
90 |
#Using Gradio Demos as API - This is Hot!
|
91 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
with gr.Tab("Diffuser"):
|
94 |
with gr.Row():
|