Design Enhancement
Browse files
app.py
CHANGED
|
@@ -3,14 +3,10 @@ from pyswip import Prolog
|
|
| 3 |
|
| 4 |
prolog = Prolog()
|
| 5 |
|
| 6 |
-
|
| 7 |
-
# 🔹 STATE (solutions cache)
|
| 8 |
-
# =========================
|
| 9 |
current_query = {"results": [], "index": 0}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
# 🔹 Charger fichier
|
| 13 |
-
# =========================
|
| 14 |
def load_file(file):
|
| 15 |
try:
|
| 16 |
prolog.consult(file.name)
|
|
@@ -18,9 +14,7 @@ def load_file(file):
|
|
| 18 |
except Exception as e:
|
| 19 |
return f"❌ Erreur: {str(e)}"
|
| 20 |
|
| 21 |
-
|
| 22 |
-
# 🔹 Lancer requête
|
| 23 |
-
# =========================
|
| 24 |
def run_query(query):
|
| 25 |
global current_query
|
| 26 |
|
|
@@ -41,9 +35,7 @@ def run_query(query):
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"❌ Erreur: {str(e)}"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
# 🔹 Next solution (;)
|
| 46 |
-
# =========================
|
| 47 |
def next_solution():
|
| 48 |
global current_query
|
| 49 |
|
|
@@ -56,21 +48,16 @@ def next_solution():
|
|
| 56 |
current_query["index"] = idx
|
| 57 |
return format_result(results[idx])
|
| 58 |
|
| 59 |
-
|
| 60 |
-
# 🔹 Format Prolog-like
|
| 61 |
-
# =========================
|
| 62 |
def format_result(res):
|
| 63 |
return " ; ".join([f"{k} = {v}" for k, v in res.items()]) + " ;"
|
| 64 |
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
# =========================
|
| 69 |
-
import gradio as gr
|
| 70 |
|
| 71 |
with gr.Blocks(title="Py-Prolog") as app:
|
| 72 |
|
| 73 |
-
# ===== Top Markdown (centralized) =====
|
| 74 |
gr.Markdown(
|
| 75 |
"""
|
| 76 |
<div style="text-align:center; margin-top:20px; color:gray;">
|
|
@@ -90,9 +77,9 @@ with gr.Blocks(title="Py-Prolog") as app:
|
|
| 90 |
status = gr.Textbox(label="📢 Etat", interactive=False)
|
| 91 |
load_btn.click(load_file, inputs=file_input, outputs=status)
|
| 92 |
|
| 93 |
-
gr.Markdown("
|
| 94 |
|
| 95 |
-
|
| 96 |
query_input = gr.Textbox(
|
| 97 |
label="Requête",
|
| 98 |
placeholder="Ex: grand_pere(X,dudulle)."
|
|
@@ -107,7 +94,7 @@ with gr.Blocks(title="Py-Prolog") as app:
|
|
| 107 |
run_btn.click(run_query, inputs=query_input, outputs=output)
|
| 108 |
next_btn.click(next_solution, outputs=output)
|
| 109 |
|
| 110 |
-
|
| 111 |
gr.Markdown(
|
| 112 |
"""
|
| 113 |
<div style="text-align:center; margin-top:20px; color:gray;">
|
|
@@ -117,7 +104,7 @@ with gr.Blocks(title="Py-Prolog") as app:
|
|
| 117 |
elem_id="footer"
|
| 118 |
)
|
| 119 |
|
| 120 |
-
|
| 121 |
app.launch(
|
| 122 |
server_name="0.0.0.0",
|
| 123 |
server_port=7860,
|
|
|
|
| 3 |
|
| 4 |
prolog = Prolog()
|
| 5 |
|
| 6 |
+
|
|
|
|
|
|
|
| 7 |
current_query = {"results": [], "index": 0}
|
| 8 |
|
| 9 |
+
|
|
|
|
|
|
|
| 10 |
def load_file(file):
|
| 11 |
try:
|
| 12 |
prolog.consult(file.name)
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
return f"❌ Erreur: {str(e)}"
|
| 16 |
|
| 17 |
+
|
|
|
|
|
|
|
| 18 |
def run_query(query):
|
| 19 |
global current_query
|
| 20 |
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"❌ Erreur: {str(e)}"
|
| 37 |
|
| 38 |
+
|
|
|
|
|
|
|
| 39 |
def next_solution():
|
| 40 |
global current_query
|
| 41 |
|
|
|
|
| 48 |
current_query["index"] = idx
|
| 49 |
return format_result(results[idx])
|
| 50 |
|
| 51 |
+
|
|
|
|
|
|
|
| 52 |
def format_result(res):
|
| 53 |
return " ; ".join([f"{k} = {v}" for k, v in res.items()]) + " ;"
|
| 54 |
|
| 55 |
|
| 56 |
+
|
| 57 |
+
|
|
|
|
|
|
|
| 58 |
|
| 59 |
with gr.Blocks(title="Py-Prolog") as app:
|
| 60 |
|
|
|
|
| 61 |
gr.Markdown(
|
| 62 |
"""
|
| 63 |
<div style="text-align:center; margin-top:20px; color:gray;">
|
|
|
|
| 77 |
status = gr.Textbox(label="📢 Etat", interactive=False)
|
| 78 |
load_btn.click(load_file, inputs=file_input, outputs=status)
|
| 79 |
|
| 80 |
+
gr.Markdown("💻 Terminal Prolog")
|
| 81 |
|
| 82 |
+
|
| 83 |
query_input = gr.Textbox(
|
| 84 |
label="Requête",
|
| 85 |
placeholder="Ex: grand_pere(X,dudulle)."
|
|
|
|
| 94 |
run_btn.click(run_query, inputs=query_input, outputs=output)
|
| 95 |
next_btn.click(next_solution, outputs=output)
|
| 96 |
|
| 97 |
+
|
| 98 |
gr.Markdown(
|
| 99 |
"""
|
| 100 |
<div style="text-align:center; margin-top:20px; color:gray;">
|
|
|
|
| 104 |
elem_id="footer"
|
| 105 |
)
|
| 106 |
|
| 107 |
+
|
| 108 |
app.launch(
|
| 109 |
server_name="0.0.0.0",
|
| 110 |
server_port=7860,
|