dromerosm commited on
Commit
a14ca86
1 Parent(s): 5363aef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -21,19 +21,22 @@ def text_prompt(request, page_url, contraseña, temp):
21
  if num_tokens > 10 and num_tokens < 2000:
22
  openai.api_key = contraseña
23
  # get the response from openai API
24
- response = openai.Completion.create(
25
- engine="text-davinci-003",
26
- prompt=request + "\n\n" + page.text,
27
- max_tokens=2048,
28
- temperature=temp,
29
- top_p=0.9,
30
- )
31
- # get the response text
32
- response_text = response.choices[0].text
33
- # clean the response text
34
- response_text = re.sub(r'\s+', ' ', response_text)
35
- return response_text, num_tokens
36
- return "--- Something went wrong! ---", num_tokens
 
 
 
37
 
38
  # define the gradio interface
39
  iface = gr.Interface(
@@ -48,4 +51,5 @@ iface = gr.Interface(
48
  ["Extract the main topics of the following text:", "https://ai.googleblog.com/2019/10/quantum-supremacy-using-programmable.html","",0.7]
49
  ]
50
  )
51
- iface.launch()
 
 
21
  if num_tokens > 10 and num_tokens < 2000:
22
  openai.api_key = contraseña
23
  # get the response from openai API
24
+ try:
25
+ response = openai.Completion.create(
26
+ engine="text-davinci-003",
27
+ prompt=request + "\n\n" + page.text,
28
+ max_tokens=2048,
29
+ temperature=temp,
30
+ top_p=0.9,
31
+ )
32
+ # get the response text
33
+ response_text = response.choices[0].text
34
+ # clean the response text
35
+ response_text = re.sub(r'\s+', ' ', response_text)
36
+ return response_text, num_tokens
37
+ except Exception as e:
38
+ return f"--- Ha ocurrido un error al procesar la solicitud: {e} ---", num_tokens
39
+ return "--- Max number of tokens ---", num_tokens
40
 
41
  # define the gradio interface
42
  iface = gr.Interface(
 
51
  ["Extract the main topics of the following text:", "https://ai.googleblog.com/2019/10/quantum-supremacy-using-programmable.html","",0.7]
52
  ]
53
  )
54
+
55
+ iface.launch(inline=False)