Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,9 +28,17 @@ try:
|
|
| 28 |
else:
|
| 29 |
backend_client = Client(BACKEND_URL)
|
| 30 |
print(f"Connected to backend at {BACKEND_URL}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
print(f"Warning: Could not connect to backend: {e}")
|
| 33 |
print(f"Make sure BACKEND_URL and HF_TOKEN are set correctly.")
|
|
|
|
|
|
|
| 34 |
backend_client = None
|
| 35 |
|
| 36 |
def add_sentences_ui(sentences_text):
|
|
@@ -41,7 +49,7 @@ def add_sentences_ui(sentences_text):
|
|
| 41 |
try:
|
| 42 |
result = backend_client.predict(
|
| 43 |
sentences_text,
|
| 44 |
-
api_name="api_add_sentences"
|
| 45 |
)
|
| 46 |
if isinstance(result, dict):
|
| 47 |
vocab_info = result.get("vocab_info", {})
|
|
@@ -62,7 +70,7 @@ def train_brain_ui(epochs, progress=gr.Progress()):
|
|
| 62 |
yield "🔄 Training in progress... Please wait..."
|
| 63 |
result = backend_client.predict(
|
| 64 |
int(epochs),
|
| 65 |
-
api_name="api_train"
|
| 66 |
)
|
| 67 |
if isinstance(result, str):
|
| 68 |
yield result
|
|
@@ -84,7 +92,7 @@ def run_stream_ui(seed_word, steps, coupling_gain, transmission_threshold):
|
|
| 84 |
int(steps),
|
| 85 |
float(coupling_gain),
|
| 86 |
float(transmission_threshold),
|
| 87 |
-
api_name="api_run_stream"
|
| 88 |
)
|
| 89 |
# Gradio returns tuple/list for multiple outputs
|
| 90 |
if isinstance(result, (list, tuple)) and len(result) >= 2:
|
|
@@ -102,7 +110,7 @@ def clear_brain_ui():
|
|
| 102 |
return "❌ Backend not available. Please check configuration.", "**Error:** Backend connection failed."
|
| 103 |
|
| 104 |
try:
|
| 105 |
-
result = backend_client.predict(api_name="api_clear_brain")
|
| 106 |
if isinstance(result, dict):
|
| 107 |
vocab_info = result.get("vocab_info", {})
|
| 108 |
vocab_text = f"**Current Vocabulary:** {vocab_info.get('vocab_size', 0)} words\n**Corpus:** {vocab_info.get('corpus_size', 0)} sentences\n**Trained:** {vocab_info.get('trained_size', 0)} sentences"
|
|
|
|
| 28 |
else:
|
| 29 |
backend_client = Client(BACKEND_URL)
|
| 30 |
print(f"Connected to backend at {BACKEND_URL}")
|
| 31 |
+
# Debug: List available API endpoints
|
| 32 |
+
try:
|
| 33 |
+
api_info = backend_client.view_api()
|
| 34 |
+
print(f"Available API endpoints: {list(api_info.keys()) if isinstance(api_info, dict) else 'Could not list APIs'}")
|
| 35 |
+
except:
|
| 36 |
+
pass
|
| 37 |
except Exception as e:
|
| 38 |
print(f"Warning: Could not connect to backend: {e}")
|
| 39 |
print(f"Make sure BACKEND_URL and HF_TOKEN are set correctly.")
|
| 40 |
+
print(f"BACKEND_URL: {BACKEND_URL}")
|
| 41 |
+
print(f"HF_TOKEN set: {bool(HF_TOKEN)}")
|
| 42 |
backend_client = None
|
| 43 |
|
| 44 |
def add_sentences_ui(sentences_text):
|
|
|
|
| 49 |
try:
|
| 50 |
result = backend_client.predict(
|
| 51 |
sentences_text,
|
| 52 |
+
api_name="/api_add_sentences"
|
| 53 |
)
|
| 54 |
if isinstance(result, dict):
|
| 55 |
vocab_info = result.get("vocab_info", {})
|
|
|
|
| 70 |
yield "🔄 Training in progress... Please wait..."
|
| 71 |
result = backend_client.predict(
|
| 72 |
int(epochs),
|
| 73 |
+
api_name="/api_train"
|
| 74 |
)
|
| 75 |
if isinstance(result, str):
|
| 76 |
yield result
|
|
|
|
| 92 |
int(steps),
|
| 93 |
float(coupling_gain),
|
| 94 |
float(transmission_threshold),
|
| 95 |
+
api_name="/api_run_stream"
|
| 96 |
)
|
| 97 |
# Gradio returns tuple/list for multiple outputs
|
| 98 |
if isinstance(result, (list, tuple)) and len(result) >= 2:
|
|
|
|
| 110 |
return "❌ Backend not available. Please check configuration.", "**Error:** Backend connection failed."
|
| 111 |
|
| 112 |
try:
|
| 113 |
+
result = backend_client.predict(api_name="/api_clear_brain")
|
| 114 |
if isinstance(result, dict):
|
| 115 |
vocab_info = result.get("vocab_info", {})
|
| 116 |
vocab_text = f"**Current Vocabulary:** {vocab_info.get('vocab_size', 0)} words\n**Corpus:** {vocab_info.get('corpus_size', 0)} sentences\n**Trained:** {vocab_info.get('trained_size', 0)} sentences"
|