Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,9 +9,10 @@ client = InferenceClient()
|
|
| 9 |
# Function to analyze plant images
|
| 10 |
def analyze_plant_image(image):
|
| 11 |
# Save image to a temporary location with appropriate extension
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
# Create the message structure
|
| 17 |
messages = [
|
|
@@ -36,7 +37,7 @@ def analyze_plant_image(image):
|
|
| 36 |
stream = client.chat.completions.create(
|
| 37 |
model="Qwen/Qwen2-VL-7B-Instruct",
|
| 38 |
messages=messages,
|
| 39 |
-
max_tokens=
|
| 40 |
stream=True
|
| 41 |
)
|
| 42 |
|
|
@@ -54,7 +55,7 @@ with gr.Blocks() as app:
|
|
| 54 |
with gr.Row():
|
| 55 |
# First column for input components
|
| 56 |
with gr.Column():
|
| 57 |
-
image_input = gr.Image(type="pil", label="Upload Plant Image", image_mode="RGB")
|
| 58 |
analyze_button = gr.Button("Analyze Plant Image")
|
| 59 |
|
| 60 |
# Second column for output
|
|
@@ -65,4 +66,4 @@ with gr.Blocks() as app:
|
|
| 65 |
analyze_button.click(fn=analyze_plant_image, inputs=image_input, outputs=output_markdown)
|
| 66 |
|
| 67 |
# Run the Gradio app
|
| 68 |
-
app.launch()
|
|
|
|
| 9 |
# Function to analyze plant images
|
| 10 |
def analyze_plant_image(image):
|
| 11 |
# Save image to a temporary location with appropriate extension
|
| 12 |
+
temp_dir = tempfile.mkdtemp()
|
| 13 |
+
temp_image_path = os.path.join(temp_dir, "uploaded_image.jpg")
|
| 14 |
+
image.save(temp_image_path, format="JPEG")
|
| 15 |
+
image_url = f"file://{temp_image_path}"
|
| 16 |
|
| 17 |
# Create the message structure
|
| 18 |
messages = [
|
|
|
|
| 37 |
stream = client.chat.completions.create(
|
| 38 |
model="Qwen/Qwen2-VL-7B-Instruct",
|
| 39 |
messages=messages,
|
| 40 |
+
max_tokens=5000,
|
| 41 |
stream=True
|
| 42 |
)
|
| 43 |
|
|
|
|
| 55 |
with gr.Row():
|
| 56 |
# First column for input components
|
| 57 |
with gr.Column():
|
| 58 |
+
image_input = gr.Image(type="pil", label="Upload Plant Image", image_mode="RGB", tool="editor")
|
| 59 |
analyze_button = gr.Button("Analyze Plant Image")
|
| 60 |
|
| 61 |
# Second column for output
|
|
|
|
| 66 |
analyze_button.click(fn=analyze_plant_image, inputs=image_input, outputs=output_markdown)
|
| 67 |
|
| 68 |
# Run the Gradio app
|
| 69 |
+
app.launch()
|