Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,6 @@ import time
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import time
|
| 7 |
-
from openai import OpenAI
|
| 8 |
-
client = OpenAI(api_key="temp")
|
| 9 |
|
| 10 |
# Set up OpenAI API key
|
| 11 |
#valapikey = ""
|
|
@@ -114,7 +112,7 @@ with gr.Blocks() as demo:
|
|
| 114 |
|
| 115 |
def checkapiinput(apikey):
|
| 116 |
if apikey != "" and apikey is not None and len(apikey) >=25 and len(apikey) <= 130:
|
| 117 |
-
|
| 118 |
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|
| 119 |
else:
|
| 120 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value="", placeholder="Use a valid API key"), gr.update(visible=False)
|
|
@@ -428,13 +426,11 @@ Now please provide your results using the following language: {language}.
|
|
| 428 |
#Now let's try 10 times
|
| 429 |
for attempt in range(10):
|
| 430 |
try:
|
| 431 |
-
|
| 432 |
-
#response = client.chat.completions.create(
|
| 433 |
-
response = client.ChatCompletion.create(
|
| 434 |
model=model,
|
| 435 |
-
|
| 436 |
)
|
| 437 |
-
result = response['choices'][0]['message']
|
| 438 |
break
|
| 439 |
except Exception as e:
|
| 440 |
print(f"Error occurred on attempt {attempt + 1}: {e}")
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import time
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Set up OpenAI API key
|
| 9 |
#valapikey = ""
|
|
|
|
| 112 |
|
| 113 |
def checkapiinput(apikey):
|
| 114 |
if apikey != "" and apikey is not None and len(apikey) >=25 and len(apikey) <= 130:
|
| 115 |
+
openai.api_key = apikey
|
| 116 |
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|
| 117 |
else:
|
| 118 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value="", placeholder="Use a valid API key"), gr.update(visible=False)
|
|
|
|
| 426 |
#Now let's try 10 times
|
| 427 |
for attempt in range(10):
|
| 428 |
try:
|
| 429 |
+
response = openai.ChatCompletion.create(
|
|
|
|
|
|
|
| 430 |
model=model,
|
| 431 |
+
messages=formattedprompt
|
| 432 |
)
|
| 433 |
+
result = response['choices'][0]['message']['content']
|
| 434 |
break
|
| 435 |
except Exception as e:
|
| 436 |
print(f"Error occurred on attempt {attempt + 1}: {e}")
|