File size: 846 Bytes
1cea1c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
import openai
from googletrans import Translator

def GPT3_Completion(prompt):
  # translate the prompt to English
  translator = Translator()
  prompt_english = translator.translate(prompt, dest='en').text
  
  openai.api_key = "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"
  response = openai.Completion.create(
  engine="text-davinci-002",
  prompt =  prompt_english,
  temperature=0.7,
  max_tokens=3500 ,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0
  )
  
  # translate the response to Spanish
  response_spanish = translator.translate(response['choices'][0]['text'], dest='es').text
  
  return response_spanish

  
inputs = gr.inputs.Textbox(placeholder="Enter prompt for GPT-3 Completion")
outputs = gr.outputs.Textbox()

interface = gr.Interface(GPT3_Completion, inputs, outputs)
interface.launch()