Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ num_classes = bundle["num_classes"]
|
|
| 27 |
class_names = bundle["class_names"]
|
| 28 |
state_dict = bundle["state_dict"]
|
| 29 |
|
| 30 |
-
device = "
|
| 31 |
model = timm.create_model(architecture, pretrained=False, num_classes=num_classes)
|
| 32 |
model.load_state_dict(state_dict)
|
| 33 |
model.eval().to(device)
|
|
@@ -110,10 +110,10 @@ def perform_text_classification_and_format(text: str):
|
|
| 110 |
|
| 111 |
predicted_text_label = str(loaded_predictor_from_hub.predict(text_df_processed).iloc[0])
|
| 112 |
if predicted_text_label == "1":
|
| 113 |
-
has_high_concept = "
|
| 114 |
confidence = text_classification_probabilities["High Concept"]
|
| 115 |
else:
|
| 116 |
-
has_high_concept = "
|
| 117 |
confidence = text_classification_probabilities["No High Concept"]
|
| 118 |
|
| 119 |
text_classification_formatted = f"High Concept: {has_high_concept} (Confidence: {confidence:.2f})"
|
|
@@ -141,27 +141,28 @@ def generate_prompt_only(image_classification_results, text_classification_proba
|
|
| 141 |
if image_classification_results and "error" not in image_classification_results:
|
| 142 |
design_stage = max(image_classification_results, key=image_classification_results.get)
|
| 143 |
|
| 144 |
-
has_high_concept = "
|
| 145 |
confidence = text_classification_probabilities.get("No High Concept", 0.0)
|
| 146 |
if predicted_text_label == "1":
|
| 147 |
-
has_high_concept = "
|
| 148 |
confidence = text_classification_probabilities.get("High Concept", 0.0)
|
| 149 |
|
| 150 |
llm_attitude = llm_attitude_mapping.get(design_stage, llm_attitude_mapping["random"])
|
| 151 |
|
| 152 |
prompt = f"""You are an abstract architecture critique interpreter.
|
| 153 |
Your audience is a low-level architecture student.
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
-
|
| 158 |
-
-
|
| 159 |
-
-
|
| 160 |
-
-
|
| 161 |
-
-
|
| 162 |
-
-
|
| 163 |
-
-
|
| 164 |
-
|
|
|
|
| 165 |
"""
|
| 166 |
return prompt
|
| 167 |
|
|
@@ -191,16 +192,20 @@ with gr.Blocks() as demo_step_by_step:
|
|
| 191 |
gr.Markdown("# Architecture Feedback Generator (Step-by-Step)")
|
| 192 |
|
| 193 |
with gr.Row():
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
def dynamic_generate_prompt(img_res, txt_prob, txt):
|
| 206 |
predicted_label = "1" if txt_prob.get("High Concept",0) > txt_prob.get("No High Concept",0) else "0"
|
|
|
|
| 27 |
class_names = bundle["class_names"]
|
| 28 |
state_dict = bundle["state_dict"]
|
| 29 |
|
| 30 |
+
device = "cpu"
|
| 31 |
model = timm.create_model(architecture, pretrained=False, num_classes=num_classes)
|
| 32 |
model.load_state_dict(state_dict)
|
| 33 |
model.eval().to(device)
|
|
|
|
| 110 |
|
| 111 |
predicted_text_label = str(loaded_predictor_from_hub.predict(text_df_processed).iloc[0])
|
| 112 |
if predicted_text_label == "1":
|
| 113 |
+
has_high_concept = "Yes"
|
| 114 |
confidence = text_classification_probabilities["High Concept"]
|
| 115 |
else:
|
| 116 |
+
has_high_concept = "No"
|
| 117 |
confidence = text_classification_probabilities["No High Concept"]
|
| 118 |
|
| 119 |
text_classification_formatted = f"High Concept: {has_high_concept} (Confidence: {confidence:.2f})"
|
|
|
|
| 141 |
if image_classification_results and "error" not in image_classification_results:
|
| 142 |
design_stage = max(image_classification_results, key=image_classification_results.get)
|
| 143 |
|
| 144 |
+
has_high_concept = "No"
|
| 145 |
confidence = text_classification_probabilities.get("No High Concept", 0.0)
|
| 146 |
if predicted_text_label == "1":
|
| 147 |
+
has_high_concept = "Yes"
|
| 148 |
confidence = text_classification_probabilities.get("High Concept", 0.0)
|
| 149 |
|
| 150 |
llm_attitude = llm_attitude_mapping.get(design_stage, llm_attitude_mapping["random"])
|
| 151 |
|
| 152 |
prompt = f"""You are an abstract architecture critique interpreter.
|
| 153 |
Your audience is a low-level architecture student.
|
| 154 |
+
The user is currently in the {design_stage} design stage, so your attitude should be {llm_attitude}.
|
| 155 |
+
The user's input contains abstract architectural concepts (Yes/No): {has_high_concept}.
|
| 156 |
+
Rules:
|
| 157 |
+
- Write a paragraph in English, strictly between 250-350 words.
|
| 158 |
+
- End with a complete sentence.
|
| 159 |
+
- Do not repeat any ideas or sentences.
|
| 160 |
+
- Do not use slogans, mottos, or parallel structures.
|
| 161 |
+
- Do not include phrases like 'final output', 'end of output', or meta-comments.
|
| 162 |
+
- Do not add self-reflection or systematic remarks.
|
| 163 |
+
- Stop immediately after the last sentence of the paragraph.
|
| 164 |
+
Here is the user input text: {text}
|
| 165 |
+
You must use simple language that a child could understand, provide everyday life examples to explain abstract concepts, and give actionable suggestions.
|
| 166 |
"""
|
| 167 |
return prompt
|
| 168 |
|
|
|
|
| 192 |
gr.Markdown("# Architecture Feedback Generator (Step-by-Step)")
|
| 193 |
|
| 194 |
with gr.Row():
|
| 195 |
+
with gr.Column():
|
| 196 |
+
image_input = gr.Image(type="pil", label="Upload Architectural Image")
|
| 197 |
+
text_input = gr.Textbox(label="Enter Text Description or Question", lines=4)
|
| 198 |
+
classify_button = gr.Button("Perform Classification & Generate Prompt")
|
| 199 |
+
|
| 200 |
+
with gr.Column():
|
| 201 |
+
image_output_label = gr.Label(num_top_classes=len(class_names), label="Image Classification Results")
|
| 202 |
+
text_output_textbox = gr.Textbox(label="Text Classification Results", lines=2)
|
| 203 |
+
text_classification_probabilities_state = gr.State()
|
| 204 |
+
prompt_output_textbox = gr.Textbox(label="Generated Prompt for LLM", interactive=True, lines=8)
|
| 205 |
+
generate_feedback_button = gr.Button("Generate Feedback from Prompt")
|
| 206 |
+
|
| 207 |
+
with gr.Column():
|
| 208 |
+
llm_output_text = gr.Textbox(label="Generated Feedback", lines=12)
|
| 209 |
|
| 210 |
def dynamic_generate_prompt(img_res, txt_prob, txt):
|
| 211 |
predicted_label = "1" if txt_prob.get("High Concept",0) > txt_prob.get("No High Concept",0) else "0"
|