chasetank commited on
Commit
80d52a8
1 Parent(s): ae51319

feat: added user input for api key

Browse files
Files changed (1) hide show
  1. app.py +46 -9
app.py CHANGED
@@ -228,8 +228,8 @@ def format_url(response) -> str:
228
  return url
229
 
230
 
231
- def main(prompt: str):
232
- client = OpenAI(api_key=OPENAI_API_KEY)
233
  tool = [{"type": "function", "function": CarParameters.openai_schema}]
234
 
235
  system_prompt = f"""
@@ -249,11 +249,48 @@ def main(prompt: str):
249
  tools=tool,
250
  tool_choice="required",
251
  )
252
- return format_url(response)
253
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
- examples = [
256
- "Im looking for a 2024 Mercedes-Benz AMG SUV with a black exterior and interior, and 17 inch wheels. Can you help me with that?"
257
- ]
258
- interface = gr.Interface(fn=main, inputs="text", outputs="text", examples=examples)
259
- interface.launch()
 
228
  return url
229
 
230
 
231
+ def main(openai_api_key: str, prompt: str) -> str:
232
+ client = OpenAI(api_key=openai_api_key)
233
  tool = [{"type": "function", "function": CarParameters.openai_schema}]
234
 
235
  system_prompt = f"""
 
249
  tools=tool,
250
  tool_choice="required",
251
  )
252
+ url = format_url(response)
253
+ markdown_link = f"[{url}]({url})"
254
+ return url, markdown_link
255
+
256
+
257
+ with gr.Blocks() as demo:
258
+ with gr.Column():
259
+ with gr.Row():
260
+ openai_api_key = gr.Textbox(
261
+ label="api-key",
262
+ placeholder="Set your OpenAI API key here and press Enter",
263
+ lines=1,
264
+ type="password",
265
+ )
266
+ with gr.Row():
267
+ with gr.Column():
268
+ prompt = gr.Textbox(
269
+ label="prompt",
270
+ placeholder="Enter your query here and press Enter",
271
+ lines=1,
272
+ )
273
+ with gr.Column():
274
+ url = gr.Textbox(
275
+ label="url",
276
+ placeholder="URL will appear here",
277
+ lines=1,
278
+ type="text",
279
+ )
280
+ with gr.Row():
281
+ link = gr.Markdown()
282
+ with gr.Row():
283
+ submit = gr.Button(value="Submit")
284
+
285
+ submit.click(fn=main, inputs=[openai_api_key, prompt], outputs=[url, link])
286
+
287
+ examples = [
288
+ "I need a car for my growing family",
289
+ "I frequently travel in snowy conditions",
290
+ "I'm an eco-conscious city dweller",
291
+ "I love high-performance sports cars",
292
+ "Im looking for a 2024 Mercedes-Benz AMG SUV with a black exterior and interior, and 17 inch wheels. Can you help me with that?",
293
+ ]
294
 
295
+ gr.Examples(examples=examples, inputs=prompt, outputs=url)
296
+ demo.launch(inline=True, debug=True)