rg321 commited on
Commit
7777fc7
·
verified ·
1 Parent(s): 02bbb64

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -1,10 +1,10 @@
1
  """
2
  Netra AI - Construction Material Classifier
3
- MVP Demo using Gemini Vision API
4
  """
5
 
6
  import gradio as gr
7
- import google.generativeai as genai
8
  import os
9
  from PIL import Image
10
  import base64
@@ -36,22 +36,45 @@ def classify_material(image):
36
  return "Please upload an image", "", ""
37
 
38
  # Get API key from environment
39
- api_key = os.getenv("GOOGLE_API_KEY", "")
40
  if not api_key:
41
  return "❌ System Error", "", "AI service not configured. Please contact support."
42
 
43
  try:
44
- # Configure Gemini
45
- genai.configure(api_key=api_key)
46
- model = genai.GenerativeModel('gemini-2.5-flash')
47
 
48
  # Convert to PIL Image if needed
49
  if not isinstance(image, Image.Image):
50
  image = Image.fromarray(image)
51
 
 
 
 
 
 
52
  # Generate classification
53
- response = model.generate_content([CLASSIFICATION_PROMPT, image])
54
- result_text = response.text.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  # Parse response
57
  lines = result_text.split('\n')
 
1
  """
2
  Netra AI - Construction Material Classifier
3
+ MVP Demo using Claude Vision API
4
  """
5
 
6
  import gradio as gr
7
+ import anthropic
8
  import os
9
  from PIL import Image
10
  import base64
 
36
  return "Please upload an image", "", ""
37
 
38
  # Get API key from environment
39
+ api_key = os.getenv("ANTHROPIC_API_KEY", "")
40
  if not api_key:
41
  return "❌ System Error", "", "AI service not configured. Please contact support."
42
 
43
  try:
44
+ # Configure Claude
45
+ client = anthropic.Anthropic(api_key=api_key)
 
46
 
47
  # Convert to PIL Image if needed
48
  if not isinstance(image, Image.Image):
49
  image = Image.fromarray(image)
50
 
51
+ # Convert image to base64
52
+ buffered = BytesIO()
53
+ image.save(buffered, format="JPEG")
54
+ image_data = base64.b64encode(buffered.getvalue()).decode("utf-8")
55
+
56
  # Generate classification
57
+ response = client.messages.create(
58
+ model="claude-opus-4-6",
59
+ max_tokens=150,
60
+ messages=[
61
+ {
62
+ "role": "user",
63
+ "content": [
64
+ {
65
+ "type": "image",
66
+ "source": {
67
+ "type": "base64",
68
+ "media_type": "image/jpeg",
69
+ "data": image_data,
70
+ },
71
+ },
72
+ {"type": "text", "text": CLASSIFICATION_PROMPT}
73
+ ],
74
+ }
75
+ ],
76
+ )
77
+ result_text = response.content[0].text.strip()
78
 
79
  # Parse response
80
  lines = result_text.split('\n')