Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ client = None
|
|
| 11 |
def initialize_client(api_key=None):
|
| 12 |
global client
|
| 13 |
api_key = os.getenv("TOGETHER_API_KEY")
|
|
|
|
| 14 |
client = Together()
|
| 15 |
|
| 16 |
def encode_image(image_path):
|
|
@@ -32,7 +33,7 @@ def bot_streaming(image_path, history):
|
|
| 32 |
|
| 33 |
prompt = """
|
| 34 |
You are expert in computer vision and autos inspection from image analysis. Inspect the auto's radiator core support for damage resulting from a front-end
|
| 35 |
-
collision. Check for any bent,
|
| 36 |
and frame sections.
|
| 37 |
Ensure that the radiator is securely mounted and assess if there are any signs of stress or deformation caused by the accident.
|
| 38 |
then tell it as accidental if not then not accidental.
|
|
@@ -82,61 +83,17 @@ def bot_streaming(image_path, history):
|
|
| 82 |
history[-1] = ("Image uploaded", error_message)
|
| 83 |
yield history
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
body_frame_data = [
|
| 87 |
-
{"label": "Radiator Core Support"},
|
| 88 |
-
{"label": "Right Strut Tower Apron"},
|
| 89 |
-
{"label": "Left Strut Tower Apron"},
|
| 90 |
-
{"label": "Right Front Rail"},
|
| 91 |
-
{"label": "Left Front Rail"},
|
| 92 |
-
{"label": "Cowl Panel Firewall"},
|
| 93 |
-
{"label": "Right A Pillar"},
|
| 94 |
-
{"label": "Left A Pillar"},
|
| 95 |
-
{"label": "Right B Pillar"},
|
| 96 |
-
{"label": "Left B Pillar"},
|
| 97 |
-
{"label": "Right C Pillar"},
|
| 98 |
-
{"label": "Left C Pillar"},
|
| 99 |
-
{"label": "Boot Floor"},
|
| 100 |
-
{"label": "Boot Lock Pillar"},
|
| 101 |
-
{"label": "Rear Sub Frame"},
|
| 102 |
-
{"label": "Front Sub Frame"},
|
| 103 |
-
]
|
| 104 |
-
|
| 105 |
-
# Define data for the Tyres
|
| 106 |
-
tyre_data = [
|
| 107 |
-
{"label": "Front Right Tyre"},
|
| 108 |
-
{"label": "Front Left Tyre"},
|
| 109 |
-
{"label": "Rear Right Tyre"},
|
| 110 |
-
{"label": "Rear Left Tyre"},
|
| 111 |
-
{"label": "Tyre Size"},
|
| 112 |
-
{"label": "Rims"},
|
| 113 |
-
{"label": "Wheel Caps"},
|
| 114 |
-
]
|
| 115 |
-
|
| 116 |
-
def create_category_section(data, name):
|
| 117 |
-
with gr.Row():
|
| 118 |
-
gr.Markdown(f"## {name}")
|
| 119 |
-
for item in data:
|
| 120 |
-
with gr.Column():
|
| 121 |
-
gr.Markdown(f"### {item['label']}")
|
| 122 |
-
image = gr.Image(type="filepath", label="Upload Image")
|
| 123 |
-
chatbot = gr.Chatbot()
|
| 124 |
-
image.upload(bot_streaming, inputs=[image, chatbot], outputs=chatbot)
|
| 125 |
-
|
| 126 |
-
# Create the main interface
|
| 127 |
with gr.Blocks() as demo:
|
| 128 |
-
gr.Markdown("#
|
| 129 |
-
gr.Markdown("Upload an image of
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
# Display Tyres Section
|
| 135 |
-
create_category_section(tyre_data, "Tyres")
|
| 136 |
|
| 137 |
-
|
| 138 |
-
clear
|
| 139 |
-
clear.click(lambda: None, None, None)
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|
| 142 |
demo.launch(debug=True)
|
|
|
|
| 11 |
def initialize_client(api_key=None):
|
| 12 |
global client
|
| 13 |
api_key = os.getenv("TOGETHER_API_KEY")
|
| 14 |
+
print(api_key)
|
| 15 |
client = Together()
|
| 16 |
|
| 17 |
def encode_image(image_path):
|
|
|
|
| 33 |
|
| 34 |
prompt = """
|
| 35 |
You are expert in computer vision and autos inspection from image analysis. Inspect the auto's radiator core support for damage resulting from a front-end
|
| 36 |
+
collision. Check for any bent, cracked, or misaligned components, including the core support bracket, mounting points,
|
| 37 |
and frame sections.
|
| 38 |
Ensure that the radiator is securely mounted and assess if there are any signs of stress or deformation caused by the accident.
|
| 39 |
then tell it as accidental if not then not accidental.
|
|
|
|
| 83 |
history[-1] = ("Image uploaded", error_message)
|
| 84 |
yield history
|
| 85 |
|
| 86 |
+
# Set up Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
+
gr.Markdown("# Radiator Accident Detection")
|
| 89 |
+
gr.Markdown("Upload an image of a radiator to determine if it shows signs of an accident")
|
| 90 |
|
| 91 |
+
chatbot = gr.Chatbot()
|
| 92 |
+
img = gr.Image(type="filepath", label="Upload Radiator Image")
|
| 93 |
+
clear = gr.Button("Clear")
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
img.upload(bot_streaming, inputs=[img, chatbot], outputs=chatbot)
|
| 96 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
|
| 97 |
|
| 98 |
if __name__ == "__main__":
|
| 99 |
demo.launch(debug=True)
|