yasserrmd commited on
Commit
0bc8e71
·
verified ·
1 Parent(s): 76c8fe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -33,19 +33,16 @@ def analyze_plant_image(image):
33
  }
34
  ]
35
 
36
- # Create a stream to receive generated content
37
- stream = client.chat_completions.create(
38
  model="Qwen/Qwen2-VL-7B-Instruct",
39
  messages=messages,
40
- max_tokens=500,
41
- stream=True
42
  )
43
 
44
- # Stream content as it is generated
45
- description = ""
46
- for chunk in stream:
47
- description += chunk["choices"][0]["delta"]["content"]
48
- yield description # Yield incremental content to display immediately
49
 
50
  # Create Gradio interface
51
  with gr.Blocks() as app:
@@ -55,7 +52,7 @@ with gr.Blocks() as app:
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")
59
  analyze_button = gr.Button("Analyze Plant Image")
60
 
61
  # Second column for output
@@ -66,4 +63,4 @@ with gr.Blocks() as app:
66
  analyze_button.click(fn=analyze_plant_image, inputs=image_input, outputs=output_markdown)
67
 
68
  # Run the Gradio app
69
- app.launch()
 
33
  }
34
  ]
35
 
36
+ # Create the completion request
37
+ completion = client.chat_completions.create(
38
  model="Qwen/Qwen2-VL-7B-Instruct",
39
  messages=messages,
40
+ max_tokens=1024
 
41
  )
42
 
43
+ # Extract the response
44
+ description = completion.choices[0].message["content"]
45
+ return description
 
 
46
 
47
  # Create Gradio interface
48
  with gr.Blocks() as app:
 
52
  with gr.Row():
53
  # First column for input components
54
  with gr.Column():
55
+ image_input = gr.Image(type="pil", label="Upload Plant Image", image_mode="RGB", tool="editor")
56
  analyze_button = gr.Button("Analyze Plant Image")
57
 
58
  # Second column for output
 
63
  analyze_button.click(fn=analyze_plant_image, inputs=image_input, outputs=output_markdown)
64
 
65
  # Run the Gradio app
66
+ app.launch(debug=True)