Rename test.py to app.py
Browse files- test.py → app.py +51 -50
test.py → app.py
RENAMED
@@ -48,6 +48,42 @@ def set_model(current_model_index):
|
|
48 |
current_model = models[current_model_index]
|
49 |
return gr.update(value=f"{current_model['name']}")
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
with gr.Blocks(theme='pikto/theme@>=0.0.1,<0.0.3') as pan:
|
53 |
gr.Markdown("AI CONTENT TOOLS.")
|
@@ -91,51 +127,16 @@ with gr.Blocks(theme='pikto/theme@>=0.0.1,<0.0.3') as pan:
|
|
91 |
API_URL_INITIAL = "https://ysharma-playground-ai-exploration.hf.space/run/initial_dataframe"
|
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 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
display: inline-flex;
|
140 |
align-items: center;
|
141 |
gap: 0.8rem;
|
@@ -147,8 +148,8 @@ with gr.Blocks(css = """#img_search img {width: 100%; height: 100%; object-fit:
|
|
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 |
-
|
151 |
-
|
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>
|
@@ -156,16 +157,16 @@ with gr.Blocks(css = """#img_search img {width: 100%; height: 100%; object-fit:
|
|
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 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
value=initial_imgs ) #initial[:-1] )
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
|
170 |
|
171 |
with gr.Tab("Diffuser"):
|
|
|
48 |
current_model = models[current_model_index]
|
49 |
return gr.update(value=f"{current_model['name']}")
|
50 |
|
51 |
+
#define inference function
|
52 |
+
#First: Get initial images for the grid display
|
53 |
+
def get_initial_images():
|
54 |
+
response = requests.post(API_URL_INITIAL, json={
|
55 |
+
"data": []
|
56 |
+
}).json()
|
57 |
+
#data = response["data"][0]['data'][0][0][:-1]
|
58 |
+
response_dict = response['data'][0]
|
59 |
+
return response_dict #, [resp[0][:-1] for resp in response["data"][0]["data"]]
|
60 |
+
|
61 |
+
#Second: Process response dictionary to get imges as hyperlinked image tags
|
62 |
+
def process_response(response_dict):
|
63 |
+
return [resp[0][:-1] for resp in response_dict["data"]]
|
64 |
+
|
65 |
+
response_dict = get_initial_images()
|
66 |
+
initial = process_response(response_dict)
|
67 |
+
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])
|
68 |
+
|
69 |
+
#Third: Load more images for the grid
|
70 |
+
def get_next10_images(response_dict, row_count):
|
71 |
+
row_count = int(row_count)
|
72 |
+
#print("(1)",type(response_dict))
|
73 |
+
#Convert the string to a dictionary
|
74 |
+
if isinstance(response_dict, dict) == False :
|
75 |
+
response_dict = ast.literal_eval(response_dict)
|
76 |
+
response = requests.post(API_URL_NEXT10, json={
|
77 |
+
"data": [response_dict, row_count ] #len(initial)-1
|
78 |
+
}).json()
|
79 |
+
row_count+=10
|
80 |
+
response_dict = response['data'][0]
|
81 |
+
#print("(2)",type(response))
|
82 |
+
#print("(3)",type(response['data'][0]))
|
83 |
+
next_set = [resp[0][:-1] for resp in response_dict["data"]]
|
84 |
+
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])
|
85 |
+
return response_dict, row_count, next_set_images #response['data'][0]
|
86 |
+
|
87 |
|
88 |
with gr.Blocks(theme='pikto/theme@>=0.0.1,<0.0.3') as pan:
|
89 |
gr.Markdown("AI CONTENT TOOLS.")
|
|
|
127 |
API_URL_INITIAL = "https://ysharma-playground-ai-exploration.hf.space/run/initial_dataframe"
|
128 |
API_URL_NEXT10 = "https://ysharma-playground-ai-exploration.hf.space/run/next_10_rows"
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
#get_next10_images(response_dict=response_dict, row_count=9)
|
132 |
#position: fixed; top: 0; left: 0; width: 100%; background-color: #fff; padding: 20px; box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
|
133 |
|
134 |
#Defining the Blocks layout
|
135 |
+
with gr.Blocks(css = """#img_search img {width: 100%; height: 100%; object-fit: cover;}""") as demo:
|
136 |
+
gr.HTML(value="top of page", elem_id="top",visible=False)
|
137 |
+
gr.HTML("""<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
138 |
+
<div
|
139 |
+
style="
|
140 |
display: inline-flex;
|
141 |
align-items: center;
|
142 |
gap: 0.8rem;
|
|
|
148 |
<div><h4 style="font-weight: 500; margin-bottom: 7px; margin-top: 5px;">
|
149 |
Stream <a href="https://github.com/playgroundai/liked_images" target="_blank">PlaygroundAI Images</a> ina beautiful grid</h4><br>
|
150 |
</div>""")
|
151 |
+
with gr.Accordion(label="Details about the working:", open=False, elem_id='accordion'):
|
152 |
+
gr.HTML("""
|
153 |
<p style="margin-bottom: 10px; font-size: 90%"><br>
|
154 |
▶️Do you see the "view api" link located in the footer of this application?
|
155 |
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>
|
|
|
157 |
▶️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.
|
158 |
</p></div>""")
|
159 |
|
160 |
+
with gr.Column(): #(elem_id = "col-container"):
|
161 |
+
b1 = gr.Button("Load More Images").style(full_width=False)
|
162 |
+
df = gr.Textbox(visible=False,elem_id='dataframe', value=response_dict)
|
163 |
+
row_count = gr.Number(visible=False, value=19 )
|
164 |
+
img_search = gr.HTML(label = 'Images from PlaygroundAI dataset', elem_id="img_search",
|
165 |
value=initial_imgs ) #initial[:-1] )
|
166 |
|
167 |
+
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>
|
168 |
+
</p></div>''')
|
169 |
+
b1.click(get_next10_images, [df, row_count], [df, row_count, img_search], api_name = "load_playgroundai_images" )
|
170 |
|
171 |
|
172 |
with gr.Tab("Diffuser"):
|