Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,41 +66,54 @@ class SafeGeocoder:
|
|
66 |
return None
|
67 |
|
68 |
# Function to just load the model
|
69 |
-
|
70 |
def load_model():
|
71 |
try:
|
72 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
payload = {
|
74 |
-
"inputs":
|
75 |
"parameters": {
|
76 |
-
"max_new_tokens":
|
77 |
"do_sample": False
|
78 |
}
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
81 |
response = requests.post(API_URL, headers=headers, json=payload)
|
82 |
|
|
|
83 |
if response.status_code == 503:
|
84 |
response_json = response.json()
|
85 |
if "error" in response_json and "loading" in response_json["error"]:
|
86 |
estimated_time = response_json.get("estimated_time", "unknown")
|
87 |
return f"⏳ Modell lädt... (ca. {int(float(estimated_time)) if isinstance(estimated_time, (int, float, str)) else 'unbekannt'} Sekunden)"
|
88 |
|
89 |
-
#
|
90 |
if response.status_code == 200:
|
91 |
-
# Make sure we got a valid response not just HTTP 200
|
92 |
result = response.json()
|
|
|
|
|
93 |
if isinstance(result, list) and len(result) > 0:
|
94 |
-
# Try to verify we got real model output
|
95 |
result_text = result[0].get("generated_text", "")
|
96 |
-
|
97 |
-
|
|
|
|
|
98 |
|
99 |
-
# If we get here,
|
100 |
-
return "⚠️ Modell
|
101 |
|
102 |
except Exception as e:
|
103 |
-
return f"❌ Fehler: {str(e)}"
|
104 |
|
105 |
def extract_info(template, text):
|
106 |
try:
|
|
|
66 |
return None
|
67 |
|
68 |
# Function to just load the model
|
69 |
+
|
70 |
def load_model():
|
71 |
try:
|
72 |
+
# Use a simple but complete example to test actual extraction
|
73 |
+
test_template = '{"test_location": ""}'
|
74 |
+
test_text = "Heute sind wir in Berlin."
|
75 |
+
|
76 |
+
prompt = f"<|input|>\n### Template:\n{test_template}\n### Text:\n{test_text}\n\n<|output|>"
|
77 |
+
|
78 |
+
# Send a complete request with a simple test case
|
79 |
payload = {
|
80 |
+
"inputs": prompt,
|
81 |
"parameters": {
|
82 |
+
"max_new_tokens": 50,
|
83 |
"do_sample": False
|
84 |
}
|
85 |
}
|
86 |
|
87 |
+
# Update status to show we're starting
|
88 |
+
gr.Info("Modell wird geladen... Dies kann einen Moment dauern.")
|
89 |
+
|
90 |
+
# Make the actual request
|
91 |
response = requests.post(API_URL, headers=headers, json=payload)
|
92 |
|
93 |
+
# Check loading status
|
94 |
if response.status_code == 503:
|
95 |
response_json = response.json()
|
96 |
if "error" in response_json and "loading" in response_json["error"]:
|
97 |
estimated_time = response_json.get("estimated_time", "unknown")
|
98 |
return f"⏳ Modell lädt... (ca. {int(float(estimated_time)) if isinstance(estimated_time, (int, float, str)) else 'unbekannt'} Sekunden)"
|
99 |
|
100 |
+
# Verify we got a proper response
|
101 |
if response.status_code == 200:
|
|
|
102 |
result = response.json()
|
103 |
+
|
104 |
+
# Check for a properly formatted extraction result
|
105 |
if isinstance(result, list) and len(result) > 0:
|
|
|
106 |
result_text = result[0].get("generated_text", "")
|
107 |
+
|
108 |
+
# Look for evidence of a completed extraction
|
109 |
+
if "<|output|>" in result_text and "Berlin" in result_text:
|
110 |
+
return "✅ Modell erfolgreich geladen und getestet! Sie können jetzt mit der Extraktion beginnen."
|
111 |
|
112 |
+
# If we get here, the model response wasn't complete
|
113 |
+
return "⚠️ Modell-Test nicht erfolgreich. Bitte versuchen Sie es erneut in einigen Sekunden."
|
114 |
|
115 |
except Exception as e:
|
116 |
+
return f"❌ Fehler beim Laden des Modells: {str(e)}"
|
117 |
|
118 |
def extract_info(template, text):
|
119 |
try:
|