dromerosm commited on
Commit
5f1e5e2
1 Parent(s): 8a074d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -19,15 +19,20 @@ def text_prompt(request, page_url, contraseña, temp):
19
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
20
 
21
  tokens = tokenizer.tokenize(page.text)
 
 
22
  num_tokens = len(tokens)
 
 
 
23
 
24
- if num_tokens > 10 and num_tokens < 2000:
25
  openai.api_key = contraseña
26
  # get the response from openai API
27
  try:
28
  response = openai.Completion.create(
29
  engine="text-davinci-003",
30
- prompt=request + "\n\n" + page.text,
31
  max_tokens=2048,
32
  temperature=temp,
33
  top_p=0.9,
@@ -39,7 +44,7 @@ def text_prompt(request, page_url, contraseña, temp):
39
  return page.text, response_text, num_tokens
40
  except Exception as e:
41
  return page.text, f"--- Ha ocurrido un error al procesar la solicitud: {e} ---", num_tokens
42
- return page.text, "--- Max number of tokens ---", num_tokens
43
 
44
  # define the gradio interface
45
  iface = gr.Interface(
 
19
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
20
 
21
  tokens = tokenizer.tokenize(page.text)
22
+
23
+ # Recortar el texto a un máximo de 1000 tokens
24
  num_tokens = len(tokens)
25
+ if num_tokens > 1800:
26
+ tokens = tokens[:1800]
27
+ page_text = " ".join(tokens)
28
 
29
+ if num_tokens > 10:
30
  openai.api_key = contraseña
31
  # get the response from openai API
32
  try:
33
  response = openai.Completion.create(
34
  engine="text-davinci-003",
35
+ prompt=request + "\n\n" + page_text,
36
  max_tokens=2048,
37
  temperature=temp,
38
  top_p=0.9,
 
44
  return page.text, response_text, num_tokens
45
  except Exception as e:
46
  return page.text, f"--- Ha ocurrido un error al procesar la solicitud: {e} ---", num_tokens
47
+ return page.text, "--- Min number of tokens ---", num_tokens
48
 
49
  # define the gradio interface
50
  iface = gr.Interface(