sugiv commited on
Commit
27cdec6
·
1 Parent(s): ffa439c

Gosh this Leetmonkey

Browse files
Files changed (1) hide show
  1. app.py +19 -42
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
- generate_interface = gr.Interface(
172
- fn=api_generate_solution,
173
- inputs=[
174
- gr.Textbox(label="LeetCode Problem Instruction"),
175
- gr.Textbox(label="JWT Token")
176
- ],
177
- outputs=gr.JSON(label="Generated Solution"),
178
- title="Generate Solution API",
179
- description="Provide a LeetCode problem instruction and a valid JWT token to generate a solution."
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
- explain_interface = gr.Interface(
194
- fn=api_explain_solution,
195
  inputs=[
196
- gr.Textbox(label="Code to Explain"),
 
197
  gr.Textbox(label="JWT Token")
198
  ],
199
- outputs=gr.JSON(label="Explanation"),
200
- title="Explain Solution API",
201
- description="Provide a code snippet and a valid JWT token to get an explanation."
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
- demo.launch(share=True)
 
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)