Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
# ADD THIS IN APP.PY
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
import os
|
| 9 |
import gradio as gr
|
| 10 |
from openai import OpenAI
|
|
@@ -12,12 +5,13 @@ from openai import OpenAI
|
|
| 12 |
# -----------------------------
|
| 13 |
# Load OpenAI key from HF Secrets
|
| 14 |
# -----------------------------
|
| 15 |
-
# In Hugging Face Spaces, Secrets/Variables are available as environment variables.
|
| 16 |
-
# Add this in your Space Settings -> Variables and secrets -> Secrets
|
| 17 |
-
# Key name: OPENAI_API_KEY
|
| 18 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 23 |
|
|
@@ -164,7 +158,8 @@ css = """
|
|
| 164 |
}
|
| 165 |
"""
|
| 166 |
|
| 167 |
-
|
|
|
|
| 168 |
# Header Row
|
| 169 |
with gr.Row():
|
| 170 |
with gr.Column(scale=1, min_width=80):
|
|
@@ -172,8 +167,6 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(), elem_id="app_container") as demo
|
|
| 172 |
value=LOGO_URL,
|
| 173 |
label=None,
|
| 174 |
show_label=False,
|
| 175 |
-
show_download_button=False,
|
| 176 |
-
show_share_button=False,
|
| 177 |
height=64,
|
| 178 |
width=64,
|
| 179 |
container=False
|
|
@@ -291,4 +284,9 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(), elem_id="app_container") as demo
|
|
| 291 |
outputs=[chatbot, state, msg]
|
| 292 |
)
|
| 293 |
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from openai import OpenAI
|
|
|
|
| 5 |
# -----------------------------
|
| 6 |
# Load OpenAI key from HF Secrets
|
| 7 |
# -----------------------------
|
|
|
|
|
|
|
|
|
|
| 8 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 9 |
|
| 10 |
+
if not OPENAI_API_KEY:
|
| 11 |
+
raise ValueError(
|
| 12 |
+
"OPENAI_API_KEY is not set. "
|
| 13 |
+
"Add it in your Hugging Face Space: Settings → Variables and secrets → Secrets."
|
| 14 |
+
)
|
| 15 |
|
| 16 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 17 |
|
|
|
|
| 158 |
}
|
| 159 |
"""
|
| 160 |
|
| 161 |
+
# Gradio 6+ expects css/theme passed to launch()
|
| 162 |
+
with gr.Blocks(elem_id="app_container") as demo:
|
| 163 |
# Header Row
|
| 164 |
with gr.Row():
|
| 165 |
with gr.Column(scale=1, min_width=80):
|
|
|
|
| 167 |
value=LOGO_URL,
|
| 168 |
label=None,
|
| 169 |
show_label=False,
|
|
|
|
|
|
|
| 170 |
height=64,
|
| 171 |
width=64,
|
| 172 |
container=False
|
|
|
|
| 284 |
outputs=[chatbot, state, msg]
|
| 285 |
)
|
| 286 |
|
| 287 |
+
# Pass theme/css here for Gradio 6+
|
| 288 |
+
demo.launch(
|
| 289 |
+
debug=False,
|
| 290 |
+
theme=gr.themes.Soft(),
|
| 291 |
+
css=css
|
| 292 |
+
)
|