Spaces:
Running
Running
Align Gradio client predictor parameters and connection imports with official docs
Browse files- app.py +1 -1
- static/app.js +14 -14
app.py
CHANGED
|
@@ -12,7 +12,7 @@ app = Server()
|
|
| 12 |
# Create static directory if it doesn't exist
|
| 13 |
os.makedirs("static", exist_ok=True)
|
| 14 |
|
| 15 |
-
@app.api()
|
| 16 |
def chat_with_step(
|
| 17 |
messages_json: str,
|
| 18 |
api_key: str,
|
|
|
|
| 12 |
# Create static directory if it doesn't exist
|
| 13 |
os.makedirs("static", exist_ok=True)
|
| 14 |
|
| 15 |
+
@app.api(name="chat_with_step")
|
| 16 |
def chat_with_step(
|
| 17 |
messages_json: str,
|
| 18 |
api_key: str,
|
static/app.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
|
| 3 |
|
| 4 |
// Global Application State Management
|
| 5 |
const STATE = {
|
|
@@ -78,9 +77,9 @@ async function initializeApp() {
|
|
| 78 |
}
|
| 79 |
|
| 80 |
// 2. Connect Gradio Client in background (Non-blocking)
|
| 81 |
-
|
| 82 |
-
.then(
|
| 83 |
-
STATE.gradioClient =
|
| 84 |
console.log("Successfully connected to Gradio.Server backend.");
|
| 85 |
})
|
| 86 |
.catch(e => {
|
|
@@ -417,17 +416,18 @@ async function triggerPromptSubmission(inputElement) {
|
|
| 417 |
const responseId = appendAssistantPlaceholderBubble();
|
| 418 |
const startTime = Date.now();
|
| 419 |
|
| 420 |
-
// Call our gradio.Server api endpoint
|
| 421 |
-
const result = await STATE.gradioClient.predict("/chat_with_step",
|
| 422 |
-
JSON.stringify(STATE.conversationHistory),
|
| 423 |
-
STATE.apiKey,
|
| 424 |
-
STATE.reasoningEffort,
|
| 425 |
-
STATE.maxTokens,
|
| 426 |
-
STATE.temperature
|
| 427 |
-
|
| 428 |
|
| 429 |
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
| 430 |
-
const
|
|
|
|
| 431 |
|
| 432 |
if (data.status === "error") {
|
| 433 |
updateAssistantBubble(responseId, `⚠️ **API Error:** ${data.message}`, "", duration);
|
|
|
|
| 1 |
+
import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
|
|
|
|
| 2 |
|
| 3 |
// Global Application State Management
|
| 4 |
const STATE = {
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
// 2. Connect Gradio Client in background (Non-blocking)
|
| 80 |
+
client(window.location.origin)
|
| 81 |
+
.then(app => {
|
| 82 |
+
STATE.gradioClient = app;
|
| 83 |
console.log("Successfully connected to Gradio.Server backend.");
|
| 84 |
})
|
| 85 |
.catch(e => {
|
|
|
|
| 416 |
const responseId = appendAssistantPlaceholderBubble();
|
| 417 |
const startTime = Date.now();
|
| 418 |
|
| 419 |
+
// Call our gradio.Server api endpoint using named object parameters matching Python arguments
|
| 420 |
+
const result = await STATE.gradioClient.predict("/chat_with_step", {
|
| 421 |
+
messages_json: JSON.stringify(STATE.conversationHistory),
|
| 422 |
+
api_key: STATE.apiKey,
|
| 423 |
+
reasoning_effort: STATE.reasoningEffort,
|
| 424 |
+
max_tokens: STATE.maxTokens,
|
| 425 |
+
temperature: STATE.temperature
|
| 426 |
+
});
|
| 427 |
|
| 428 |
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
|
| 429 |
+
const rawData = Array.isArray(result.data) ? result.data[0] : result.data;
|
| 430 |
+
const data = JSON.parse(rawData);
|
| 431 |
|
| 432 |
if (data.status === "error") {
|
| 433 |
updateAssistantBubble(responseId, `⚠️ **API Error:** ${data.message}`, "", duration);
|