Spaces:
Sleeping
Sleeping
Pavlo Kostianov
commited on
Commit
·
c944dd0
1
Parent(s):
c002d00
Replace Gemini with OpenAI
Browse files
app.py
CHANGED
|
@@ -2,11 +2,12 @@ import pandas as pd
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# 1. Configure Gemini
|
| 8 |
-
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 9 |
-
model = genai.GenerativeModel("gemini-2.5-flash")
|
| 10 |
|
| 11 |
# 2. Load Excel data
|
| 12 |
# Load all sheets
|
|
@@ -177,9 +178,17 @@ Rules:
|
|
| 177 |
"""
|
| 178 |
|
| 179 |
try:
|
| 180 |
-
# Ask
|
| 181 |
-
response =
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
# Strip markdown fences if any
|
| 185 |
if code.startswith("```"):
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
+
import openai # requires OPENAI_API_KEY set as env var
|
| 6 |
+
|
| 7 |
+
# 1. Configure OpenAI
|
| 8 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 9 |
+
MODEL_NAME = "gpt-5"
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# 2. Load Excel data
|
| 13 |
# Load all sheets
|
|
|
|
| 178 |
"""
|
| 179 |
|
| 180 |
try:
|
| 181 |
+
# Ask OpenAI
|
| 182 |
+
response = openai.ChatCompletion.create(
|
| 183 |
+
model=MODEL_NAME,
|
| 184 |
+
messages=[
|
| 185 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 186 |
+
{"role": "user", "content": prompt}
|
| 187 |
+
],
|
| 188 |
+
temperature=0.2,
|
| 189 |
+
max_tokens=1200
|
| 190 |
+
)
|
| 191 |
+
code = response.choices[0].message["content"].strip()
|
| 192 |
|
| 193 |
# Strip markdown fences if any
|
| 194 |
if code.startswith("```"):
|