Gosh this Leetmonkey
Browse files
app.py
CHANGED
@@ -168,52 +168,29 @@ def api_random_problem(token: str) -> Dict[str, Any]:
|
|
168 |
|
169 |
return {"problem": select_random_problem()}
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
stream_interface = gr.Interface(
|
183 |
-
fn=api_stream_solution,
|
184 |
-
inputs=[
|
185 |
-
gr.Textbox(label="LeetCode Problem Instruction"),
|
186 |
-
gr.Textbox(label="JWT Token")
|
187 |
-
],
|
188 |
-
outputs=gr.JSON(label="Streamed Solution"),
|
189 |
-
title="Stream Solution API",
|
190 |
-
description="Provide a LeetCode problem instruction and a valid JWT token to stream a solution."
|
191 |
-
)
|
192 |
|
193 |
-
|
194 |
-
fn=
|
195 |
inputs=[
|
196 |
-
gr.Textbox(label="
|
|
|
197 |
gr.Textbox(label="JWT Token")
|
198 |
],
|
199 |
-
outputs=gr.JSON(label="
|
200 |
-
title="
|
201 |
-
description="Provide
|
202 |
-
)
|
203 |
-
|
204 |
-
random_problem_interface = gr.Interface(
|
205 |
-
fn=api_random_problem,
|
206 |
-
inputs=[gr.Textbox(label="JWT Token")],
|
207 |
-
outputs=gr.JSON(label="Random Problem"),
|
208 |
-
title="Random Problem API",
|
209 |
-
description="Provide a valid JWT token to get a random LeetCode problem."
|
210 |
-
)
|
211 |
-
|
212 |
-
# Combine interfaces
|
213 |
-
demo = gr.TabbedInterface(
|
214 |
-
[generate_interface, stream_interface, explain_interface, random_problem_interface],
|
215 |
-
["Generate Solution", "Stream Solution", "Explain Solution", "Random Problem"]
|
216 |
)
|
217 |
|
218 |
if __name__ == "__main__":
|
219 |
-
|
|
|
168 |
|
169 |
return {"problem": select_random_problem()}
|
170 |
|
171 |
+
def gradio_api(api_name: str, *args):
|
172 |
+
if api_name == "generate_solution":
|
173 |
+
return api_generate_solution(*args)
|
174 |
+
elif api_name == "stream_solution":
|
175 |
+
return api_stream_solution(*args)
|
176 |
+
elif api_name == "explain_solution":
|
177 |
+
return api_explain_solution(*args)
|
178 |
+
elif api_name == "random_problem":
|
179 |
+
return api_random_problem(*args)
|
180 |
+
else:
|
181 |
+
return {"error": "Invalid API name"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
+
iface = gr.Interface(
|
184 |
+
fn=gradio_api,
|
185 |
inputs=[
|
186 |
+
gr.Textbox(label="API Name"),
|
187 |
+
gr.Textbox(label="Problem Instruction"),
|
188 |
gr.Textbox(label="JWT Token")
|
189 |
],
|
190 |
+
outputs=gr.JSON(label="API Response"),
|
191 |
+
title="LeetCode Problem Solver API",
|
192 |
+
description="Provide the API name, problem instruction (if required), and JWT token to use the desired functionality."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
)
|
194 |
|
195 |
if __name__ == "__main__":
|
196 |
+
iface.launch(share=True)
|