Shubhy commited on
Commit
5f738f9
1 Parent(s): 7feffed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -7,16 +7,23 @@ openai.api_key = "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"
7
  # Define the function to handle the user's inputs and generate the output
8
  def process_quote(quote, action):
9
  if action == "find author":
10
- # Code to find the author of the quote
11
- # You can replace this with your own logic or API call
12
- author = "John Doe"
 
 
 
 
 
 
 
13
  return f"The author of the quote '{quote}' is {author}."
14
  elif action == "explain quote":
15
  # Call OpenAI API to explain the quote
16
  response = openai.Completion.create(
17
  engine="text-davinci-003",
18
  prompt=f"Explain the quote: '{quote}'",
19
- max_tokens=50,
20
  n=1,
21
  stop=None,
22
  temperature=0.7
@@ -24,7 +31,7 @@ def process_quote(quote, action):
24
  explanation = response.choices[0].text.strip()
25
  return f"Explanation of the quote '{quote}': {explanation}."
26
  elif action == "generate similar quote":
27
- # Call OpenAI API to generate a similar quote
28
  response = openai.Completion.create(
29
  engine="text-davinci-003",
30
  prompt=quote,
@@ -34,9 +41,8 @@ def process_quote(quote, action):
34
  temperature=0.7
35
  )
36
  similar_quote = response.choices[0].text.strip()
37
- return f"A similar quote to '{quote}' is: {similar_quote}."
38
 
39
- # Create the Gradio interface
40
  quote_input = gr.inputs.Textbox(label="Enter a quote")
41
  action_input = gr.inputs.Dropdown(["find author", "explain quote", "generate similar quote"], label="Select an action")
42
  output_text = gr.outputs.Textbox()
@@ -44,4 +50,4 @@ output_text = gr.outputs.Textbox()
44
  interface = gr.Interface(fn=process_quote, inputs=[quote_input, action_input], outputs=output_text)
45
 
46
  # Run the interface
47
- interface.launch()
 
7
  # Define the function to handle the user's inputs and generate the output
8
  def process_quote(quote, action):
9
  if action == "find author":
10
+ # Call OpenAI API to find the author of the quote
11
+ response = openai.Completion.create(
12
+ engine="text-davinci-003",
13
+ prompt=f"Find the author of the quote: '{quote}'",
14
+ max_tokens=30,
15
+ n=1,
16
+ stop=None,
17
+ temperature=0.7
18
+ )
19
+ author = response.choices[0].text.strip()
20
  return f"The author of the quote '{quote}' is {author}."
21
  elif action == "explain quote":
22
  # Call OpenAI API to explain the quote
23
  response = openai.Completion.create(
24
  engine="text-davinci-003",
25
  prompt=f"Explain the quote: '{quote}'",
26
+ max_tokens=100,
27
  n=1,
28
  stop=None,
29
  temperature=0.7
 
31
  explanation = response.choices[0].text.strip()
32
  return f"Explanation of the quote '{quote}': {explanation}."
33
  elif action == "generate similar quote":
34
+ # Call OpenAI API to generate a similar quote with fewer tokens
35
  response = openai.Completion.create(
36
  engine="text-davinci-003",
37
  prompt=quote,
 
41
  temperature=0.7
42
  )
43
  similar_quote = response.choices[0].text.strip()
44
+ return f"A similar quote to '{quote}': {similar_quote}."
45
 
 
46
  quote_input = gr.inputs.Textbox(label="Enter a quote")
47
  action_input = gr.inputs.Dropdown(["find author", "explain quote", "generate similar quote"], label="Select an action")
48
  output_text = gr.outputs.Textbox()
 
50
  interface = gr.Interface(fn=process_quote, inputs=[quote_input, action_input], outputs=output_text)
51
 
52
  # Run the interface
53
+ interface.launch()