Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -98,8 +98,47 @@ Provide a concise explanation for the classification, referencing key problem fe
|
|
98 |
|
99 |
Your Classification and Explanation:
|
100 |
''')
|
101 |
-
|
|
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
iface = gr.Interface(
|
104 |
fn=pvsnp,
|
105 |
inputs=gr.Textbox(label="What problem would you like to classify as P or NP?"),
|
@@ -111,4 +150,29 @@ iface = gr.Interface(
|
|
111 |
)
|
112 |
|
113 |
# Launch the app
|
114 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
Your Classification and Explanation:
|
100 |
''')
|
101 |
+
|
102 |
+
return classification
|
103 |
|
104 |
+
def critic_analysis(classification_output):
|
105 |
+
critic = model_response(f'''"You are PolyCritic, an expert in computational complexity and problem decomposition. Your goal is to critically evaluate whether a given
|
106 |
+
NP-hard problem, when broken into P-solvable subproblems, can be efficiently recombined to yield the full solution. Here is the problem and the analysis: {classification}
|
107 |
+
|
108 |
+
Instructions:
|
109 |
+
1️⃣ Input: A decomposed NP-hard problem along with its P-solvable subproblems.
|
110 |
+
2️⃣ Step 1 - Validate Subproblems:
|
111 |
+
|
112 |
+
Do these subproblems fully cover the original problem?
|
113 |
+
|
114 |
+
Are they correctly categorized as P?
|
115 |
+
3️⃣ Step 2 - Analyze Recombination Complexity:
|
116 |
+
|
117 |
+
Can the subproblem solutions be combined in polynomial time?
|
118 |
+
|
119 |
+
If not, what is the bottleneck? (e.g., exponential merging, missing constraints)
|
120 |
+
4️⃣ Step 3 - Provide Verdict:
|
121 |
+
|
122 |
+
If recombination is efficient, explain why this suggests progress towards P = NP.
|
123 |
+
|
124 |
+
If inefficient, identify where complexity remains and suggest next steps.
|
125 |
+
5️⃣ Step 4 - Provide Complexity Insights:
|
126 |
+
|
127 |
+
Offer insights into whether certain structural patterns predict efficient recombination.
|
128 |
+
|
129 |
+
Suggest improvements in decomposition strategies.
|
130 |
+
|
131 |
+
Example Analysis Format:
|
132 |
+
💡 Problem: Traveling Salesperson (TSP)
|
133 |
+
🔍 Subproblems: Shortest paths between city clusters (P-solvable)
|
134 |
+
⚖ Recombination Complexity: Exponential growth in possible paths when merging clusters
|
135 |
+
🚨 Verdict: Recombination remains NP-hard → Decomposition needs refinement
|
136 |
+
|
137 |
+
👉 Your task is to apply this structured critique to any NP-hard problem and determine if it truly reduces to P.''')
|
138 |
+
return critic
|
139 |
+
|
140 |
+
|
141 |
+
'''
|
142 |
iface = gr.Interface(
|
143 |
fn=pvsnp,
|
144 |
inputs=gr.Textbox(label="What problem would you like to classify as P or NP?"),
|
|
|
150 |
)
|
151 |
|
152 |
# Launch the app
|
153 |
+
iface.launch() '''
|
154 |
+
|
155 |
+
with gr.Blocks() as app:
|
156 |
+
gr.Markdown("# PolyProb & PolyCritic AI 🤖")
|
157 |
+
gr.Markdown('''PolyProb and PolyCritic are AI Agents that help users classify a problem into categories such as P, NP, NP-complete, NP-hard while
|
158 |
+
providing clear, concise explanations of its reasoning. As part of AI Quotient’s Millennium Math Challenge, it is the first step towards solving the P vs NP problem.''')
|
159 |
+
|
160 |
+
with gr.Row():
|
161 |
+
problem_input = gr.Textbox(label="Enter a computational problem")
|
162 |
+
classify_button = gr.Button("Classify")
|
163 |
+
|
164 |
+
classification_output = gr.Markdown(label="Classification (P or NP)")
|
165 |
+
|
166 |
+
classify_button.click(pvnsp, inputs=problem_input, outputs=[classification_output])
|
167 |
+
|
168 |
+
evaluate_button = gr.Button("Evaluate Recombination Complexity")
|
169 |
+
recombination_output = gr.Textbox(label="Recombination Complexity")
|
170 |
+
|
171 |
+
evaluate_button.click(critic_analysis, inputs=classification_output, outputs=recombination_output)
|
172 |
+
|
173 |
+
#results_button = gr.Button("Show Stored Results")
|
174 |
+
#results_display = gr.Textbox(label="Stored Results")
|
175 |
+
|
176 |
+
#results_button.click(get_stored_results, outputs=results_display)
|
177 |
+
|
178 |
+
app.launch(theme = gr.themes.Ocean())
|