Add Py Prolog Files
Browse files
app.py
CHANGED
|
@@ -62,28 +62,37 @@ def next_solution():
|
|
| 62 |
def format_result(res):
|
| 63 |
return " ; ".join([f"{k} = {v}" for k, v in res.items()]) + " ;"
|
| 64 |
|
|
|
|
| 65 |
# =========================
|
| 66 |
# 🎨 Interface moderne
|
| 67 |
# =========================
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
gr.Markdown("""
|
| 71 |
-
# 🧠 Py-Prolog
|
| 72 |
-
### Mini SWI-Prolog en Python (Powered by PySwip)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
|
|
|
| 77 |
with gr.Row():
|
| 78 |
file_input = gr.File(label="📂 Charger fichier Prolog (.pl)")
|
| 79 |
load_btn = gr.Button("⚡ Charger", variant="primary")
|
| 80 |
|
| 81 |
status = gr.Textbox(label="📢 Etat", interactive=False)
|
| 82 |
-
|
| 83 |
load_btn.click(load_file, inputs=file_input, outputs=status)
|
| 84 |
|
| 85 |
gr.Markdown("## 💻 Terminal Prolog")
|
| 86 |
|
|
|
|
| 87 |
query_input = gr.Textbox(
|
| 88 |
label="Requête",
|
| 89 |
placeholder="Ex: grand_pere(X,dudulle)."
|
|
@@ -98,5 +107,60 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Py-Prolog") as app:
|
|
| 98 |
run_btn.click(run_query, inputs=query_input, outputs=output)
|
| 99 |
next_btn.click(next_solution, outputs=output)
|
| 100 |
|
| 101 |
-
#
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def format_result(res):
|
| 63 |
return " ; ".join([f"{k} = {v}" for k, v in res.items()]) + " ;"
|
| 64 |
|
| 65 |
+
|
| 66 |
# =========================
|
| 67 |
# 🎨 Interface moderne
|
| 68 |
# =========================
|
| 69 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
with gr.Blocks() as app: # theme and title moved to launch()
|
| 72 |
+
|
| 73 |
+
# ===== Top Markdown (centralized) =====
|
| 74 |
+
gr.Markdown(
|
| 75 |
+
"""
|
| 76 |
+
<div style="text-align:center">
|
| 77 |
+
# 🧠 Py-Prolog
|
| 78 |
+
### Mini SWI-Prolog en Python (Powered by PySwip)
|
| 79 |
+
Charger un fichier `.pl`, puis exécuter des requêtes comme en Prolog.
|
| 80 |
+
</div>
|
| 81 |
+
""",
|
| 82 |
+
elem_id="top-markdown"
|
| 83 |
+
)
|
| 84 |
|
| 85 |
+
# ===== File loader =====
|
| 86 |
with gr.Row():
|
| 87 |
file_input = gr.File(label="📂 Charger fichier Prolog (.pl)")
|
| 88 |
load_btn = gr.Button("⚡ Charger", variant="primary")
|
| 89 |
|
| 90 |
status = gr.Textbox(label="📢 Etat", interactive=False)
|
|
|
|
| 91 |
load_btn.click(load_file, inputs=file_input, outputs=status)
|
| 92 |
|
| 93 |
gr.Markdown("## 💻 Terminal Prolog")
|
| 94 |
|
| 95 |
+
# ===== Query input =====
|
| 96 |
query_input = gr.Textbox(
|
| 97 |
label="Requête",
|
| 98 |
placeholder="Ex: grand_pere(X,dudulle)."
|
|
|
|
| 107 |
run_btn.click(run_query, inputs=query_input, outputs=output)
|
| 108 |
next_btn.click(next_solution, outputs=output)
|
| 109 |
|
| 110 |
+
# ===== Footer =====
|
| 111 |
+
gr.Markdown(
|
| 112 |
+
"""
|
| 113 |
+
<div style="text-align:center; margin-top:20px; color:gray;">
|
| 114 |
+
Developed by Cheikh Ahmed Telmoud
|
| 115 |
+
</div>
|
| 116 |
+
""",
|
| 117 |
+
elem_id="footer"
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# 🔥 Launch with theme and title (Gradio 6+)
|
| 121 |
+
app.launch(
|
| 122 |
+
server_name="0.0.0.0",
|
| 123 |
+
server_port=7860,
|
| 124 |
+
theme=gr.themes.Soft(),
|
| 125 |
+
title="Py-Prolog",
|
| 126 |
+
debug=True
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
# # =========================
|
| 130 |
+
# # 🎨 Interface moderne
|
| 131 |
+
# # =========================
|
| 132 |
+
# with gr.Blocks(theme=gr.themes.Soft(), title="Py-Prolog") as app:
|
| 133 |
+
|
| 134 |
+
# gr.Markdown("""
|
| 135 |
+
# # 🧠 Py-Prolog
|
| 136 |
+
# ### Mini SWI-Prolog en Python (Powered by PySwip)
|
| 137 |
+
|
| 138 |
+
# Charger un fichier `.pl`, puis exécuter des requêtes comme en Prolog.
|
| 139 |
+
# """)
|
| 140 |
+
|
| 141 |
+
# with gr.Row():
|
| 142 |
+
# file_input = gr.File(label="📂 Charger fichier Prolog (.pl)")
|
| 143 |
+
# load_btn = gr.Button("⚡ Charger", variant="primary")
|
| 144 |
+
|
| 145 |
+
# status = gr.Textbox(label="📢 Etat", interactive=False)
|
| 146 |
+
|
| 147 |
+
# load_btn.click(load_file, inputs=file_input, outputs=status)
|
| 148 |
+
|
| 149 |
+
# gr.Markdown("## 💻 Terminal Prolog")
|
| 150 |
+
|
| 151 |
+
# query_input = gr.Textbox(
|
| 152 |
+
# label="Requête",
|
| 153 |
+
# placeholder="Ex: grand_pere(X,dudulle)."
|
| 154 |
+
# )
|
| 155 |
+
|
| 156 |
+
# with gr.Row():
|
| 157 |
+
# run_btn = gr.Button("▶ Exécuter", variant="primary")
|
| 158 |
+
# next_btn = gr.Button("➡ Next ( ; )")
|
| 159 |
+
|
| 160 |
+
# output = gr.Textbox(label="Résultat", lines=5)
|
| 161 |
+
|
| 162 |
+
# run_btn.click(run_query, inputs=query_input, outputs=output)
|
| 163 |
+
# next_btn.click(next_solution, outputs=output)
|
| 164 |
+
|
| 165 |
+
# # 🔥 IMPORTANT (évite erreurs asyncio)
|
| 166 |
+
# app.launch(server_name="0.0.0.0", server_port=7860)
|