Update app.py
Browse files
app.py
CHANGED
@@ -8,10 +8,9 @@ import base64
|
|
8 |
|
9 |
# Set API key
|
10 |
#base_url = os.environ.get("OPENAI_API_BASE")
|
11 |
-
api_key = ""
|
12 |
|
13 |
# Define the model to be used
|
14 |
-
|
15 |
|
16 |
DESCRIPTION = '''
|
17 |
<div>
|
@@ -37,20 +36,22 @@ footer {
|
|
37 |
|
38 |
def endpoints(api_key):
|
39 |
if api_key is not None:
|
40 |
-
if api_key.startswith(
|
41 |
model_name = "gpt-4o"
|
42 |
-
|
|
|
43 |
else:
|
44 |
model_name = "models/gemini-1.5-pro-latest"
|
45 |
-
|
|
|
46 |
|
47 |
def read(filename):
|
48 |
with open(filename) as f:
|
49 |
data = f.read()
|
50 |
return data
|
51 |
|
52 |
-
def process_text(text_input, unit):
|
53 |
-
endpoint = endpoints(api_key)
|
54 |
if text_input and endpoint == 'OPENAI':
|
55 |
client = OpenAI(api_key=api_key)
|
56 |
completion = client.chat.completions.create(
|
@@ -75,8 +76,8 @@ def encode_image_to_base64(image_input):
|
|
75 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
76 |
return img_str
|
77 |
|
78 |
-
def process_image(image_input, unit):
|
79 |
-
endpoint = endpoints(api_key)
|
80 |
if image_input is not None and endpoint == 'OPENAI':
|
81 |
client = OpenAI(api_key=api_key)
|
82 |
#with open(image_input.name, "rb") as f:
|
|
|
8 |
|
9 |
# Set API key
|
10 |
#base_url = os.environ.get("OPENAI_API_BASE")
|
|
|
11 |
|
12 |
# Define the model to be used
|
13 |
+
|
14 |
|
15 |
DESCRIPTION = '''
|
16 |
<div>
|
|
|
36 |
|
37 |
def endpoints(api_key):
|
38 |
if api_key is not None:
|
39 |
+
if api_key.startswith('sk-'):
|
40 |
model_name = "gpt-4o"
|
41 |
+
endpoint = 'OPENAI'
|
42 |
+
return model_name, endpoint
|
43 |
else:
|
44 |
model_name = "models/gemini-1.5-pro-latest"
|
45 |
+
endpoint = 'GOOGLE'
|
46 |
+
return model_name, endpoint
|
47 |
|
48 |
def read(filename):
|
49 |
with open(filename) as f:
|
50 |
data = f.read()
|
51 |
return data
|
52 |
|
53 |
+
def process_text(api_key, text_input, unit):
|
54 |
+
model_name, endpoint = endpoints(api_key)
|
55 |
if text_input and endpoint == 'OPENAI':
|
56 |
client = OpenAI(api_key=api_key)
|
57 |
completion = client.chat.completions.create(
|
|
|
76 |
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
77 |
return img_str
|
78 |
|
79 |
+
def process_image(api_key, image_input, unit):
|
80 |
+
model_name, endpoint = endpoints(api_key)
|
81 |
if image_input is not None and endpoint == 'OPENAI':
|
82 |
client = OpenAI(api_key=api_key)
|
83 |
#with open(image_input.name, "rb") as f:
|