salomonsky commited on
Commit
972a12b
1 Parent(s): fdbf59c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,23 +1,28 @@
 
1
  import gradio as gr
2
  import os
3
  import subprocess
4
  from gtts import gTTS
5
  from pydub import AudioSegment
6
- from transformers import GPT2LMHeadModel, GPT2Tokenizer, pipeline
7
  from PIL import Image
8
 
9
- generator = pipeline('text-generation', model="checkpoints")
10
- tokenizer = GPT2Tokenizer.from_pretrained('checkpoints')
11
  os.environ["TOKENIZERS_PARALLELISM"] = "true"
12
 
13
  def generate_output(name, date_of_birth, progress=gr.Progress()):
14
- prompt = f"Bienvenido {name}:"
15
- input_tokens = tokenizer.encode(prompt, add_special_tokens=True)
16
- input_text = tokenizer.decode(input_tokens)
17
- gpt2_output = generator(input_text, max_length=60, do_sample=True, temperature=0.6)
18
- generated_text = gpt2_output[0]['generated_text']
19
- generated_text = generated_text.replace(input_text, "").strip()
20
- if len(gpt2_output) == 0 or 'generated_text' not in gpt2_output[0]:
 
 
 
 
 
21
  return None, "No se pudo generar el texto."
22
 
23
  def _progress(generated, to_generate):
 
1
+ import openai
2
  import gradio as gr
3
  import os
4
  import subprocess
5
  from gtts import gTTS
6
  from pydub import AudioSegment
 
7
  from PIL import Image
8
 
9
+ openai.api_key = "openai_key" # Reemplaza "openai_key" con el nombre de tu clave de API de OpenAI
10
+
11
  os.environ["TOKENIZERS_PARALLELISM"] = "true"
12
 
13
  def generate_output(name, date_of_birth, progress=gr.Progress()):
14
+ prompt = f"{name}, tu mi or谩culo astrol贸gico de hoy es:"
15
+ response = openai.Completion.create(
16
+ engine="text-davinci-003",
17
+ prompt=prompt,
18
+ max_tokens=60,
19
+ temperature=0.6,
20
+ n=1,
21
+ stop=None,
22
+ )
23
+ gpt3_output = response.choices[0].text.strip()
24
+ generated_text = gpt3_output.replace(prompt, "").strip()
25
+ if len(response.choices) == 0 or 'text' not in response.choices[0]:
26
  return None, "No se pudo generar el texto."
27
 
28
  def _progress(generated, to_generate):