Skip to content

Commit f40288e

Browse files
authored
Merge pull request #73 from stackhpc/feat/gradio-v5
Upgrade web apps to Gradio v5
2 parents ad40723 + dac0ac2 commit f40288e

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

web-apps/chat/app.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ def inference(latest_message, history):
130130
raise gr.Error("Unexpected error encountered - see logs for details.")
131131

132132

133-
# UI theming
134-
theme = gr.themes.Default(**settings.theme_params)
135-
theme.set(**settings.theme_params_extended)
136-
137-
138133
def inference_wrapper(*args):
139134
"""
140135
Simple wrapper round the `inference` function which catches certain predictable errors
@@ -152,30 +147,26 @@ def inference_wrapper(*args):
152147
yield chunk
153148

154149

155-
# Build main chat interface
156-
app = gr.ChatInterface(
157-
inference_wrapper,
158-
chatbot=gr.Chatbot(
159-
# Height of conversation window in CSS units (string) or pixels (int)
160-
height="68vh",
161-
show_copy_button=True,
162-
),
163-
textbox=gr.Textbox(
164-
placeholder="Ask me anything...",
165-
container=False,
166-
# Ratio of text box to submit button width
167-
scale=7,
168-
),
169-
title=settings.page_title,
170-
retry_btn="Retry",
171-
undo_btn="Undo",
172-
clear_btn="Clear",
173-
analytics_enabled=False,
150+
# UI theming
151+
theme = gr.themes.Default(**settings.theme_params)
152+
theme.set(**settings.theme_params_extended)
153+
154+
with gr.Blocks(
155+
fill_height=True,
174156
theme=theme,
175157
css=settings.css_overrides,
176-
js=settings.custom_javascript,
177-
)
178-
log.debug("Gradio chat interface config: %s", app.config)
179-
app.queue(
180-
default_concurrency_limit=10,
181-
).launch(server_name=settings.host_address)
158+
js=settings.custom_javascript
159+
) as demo:
160+
gr.ChatInterface(
161+
inference_wrapper,
162+
type="messages",
163+
title=settings.page_title,
164+
analytics_enabled=False,
165+
)
166+
167+
168+
if __name__ == "__main__":
169+
log.debug("Gradio chat interface config: %s", demo.config)
170+
demo.queue(
171+
default_concurrency_limit=10,
172+
).launch(server_name=settings.host_address)

web-apps/chat/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
gradio<5
1+
gradio<6
22
gradio_client
33
openai
44
langchain

web-apps/image-analysis/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def analyze_image(image_url, prompt):
115115
gr.Textbox(label="Prompt/Question", elem_id="prompt", scale=2),
116116
],
117117
outputs=[gr.Image(label="Image"), gr.Textbox(label="Results")],
118-
allow_flagging='never',
118+
flagging_mode='never',
119119
title=settings.page_title,
120120
description=settings.page_description,
121121
examples=[[ex.image_url, ex.prompt] for ex in settings.examples],

web-apps/image-analysis/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pillow
22
requests
3-
gradio<5
3+
gradio<6
44
gradio_client
55
pydantic
66
structlog

0 commit comments

Comments
 (0)