Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,18 @@ def extract_info(sentence):
|
|
25 |
headers={"Authorization": f"Bearer {HF_API_TOKEN}"},
|
26 |
json={"inputs": prompt}
|
27 |
)
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# Gradio UI
|
31 |
iface = gr.Interface(
|
|
|
25 |
headers={"Authorization": f"Bearer {HF_API_TOKEN}"},
|
26 |
json={"inputs": prompt}
|
27 |
)
|
28 |
+
result = response.json()
|
29 |
+
generated_text = result[0]["generated_text"]
|
30 |
+
|
31 |
+
# Try to extract JSON object from the generated text
|
32 |
+
match = re.search(r'\{.*\}', generated_text, re.DOTALL)
|
33 |
+
if match:
|
34 |
+
try:
|
35 |
+
return json.loads(match.group())
|
36 |
+
except json.JSONDecodeError:
|
37 |
+
return {"error": "Failed to parse JSON"}
|
38 |
+
else:
|
39 |
+
return {"error": "No JSON found in model response"}
|
40 |
|
41 |
# Gradio UI
|
42 |
iface = gr.Interface(
|