Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
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 |
-
|
|
|
|
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)
|