Abhishek commited on
Commit
5a780b3
1 Parent(s): 0167384

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -3,27 +3,29 @@ import gradio
3
 
4
  openai.api_key = "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"
5
 
6
- def generate_product_name(prompt):
7
  model_engine = "text-davinci-003"
8
  prompt = (f"{prompt} \n\n Generated product names: \n\n")
9
 
10
- completions = openai.Completion.create(
11
- engine=model_engine,
12
- prompt=prompt,
13
- max_tokens=1024,
14
- n=1,
15
- stop=None,
16
- temperature=0.5,
17
- )
18
-
 
 
 
19
 
20
- message = completions.choices[0].text.strip()
21
- return message
22
 
23
  iface = gradio.Interface(
24
  fn=generate_product_name,
25
- inputs="text",
26
- outputs="json",
27
  title="Product Name Generator",
28
  flagging=False
29
  )
 
3
 
4
  openai.api_key = "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"
5
 
6
+ def generate_product_name(prompt, num_names=5):
7
  model_engine = "text-davinci-003"
8
  prompt = (f"{prompt} \n\n Generated product names: \n\n")
9
 
10
+ product_names = []
11
+ for _ in range(num_names):
12
+ completions = openai.Completion.create(
13
+ engine=model_engine,
14
+ prompt=prompt,
15
+ max_tokens=1024,
16
+ n=1,
17
+ stop=None,
18
+ temperature=0.5,
19
+ )
20
+ message = completions.choices[0].text.strip()
21
+ product_names.append(message)
22
 
23
+ return product_names
 
24
 
25
  iface = gradio.Interface(
26
  fn=generate_product_name,
27
+ inputs=["text", gradio.inputs.Number(default=5, label="Number of product names")],
28
+ outputs="text",
29
  title="Product Name Generator",
30
  flagging=False
31
  )