Afeezee commited on
Commit
f8ffbef
·
verified ·
1 Parent(s): cff9059

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -1,19 +1,20 @@
1
  import os
2
  import gradio as gr
3
  import requests
4
- from groq import Groq
 
5
 
6
- # Initialize Groq client
7
- visionkey = os.getenv("GroqVision") # Your Groq Vision API key from environment variables
8
- client = Groq(api_key=visionkey)
9
 
10
- # Your imgbb API key
11
- imagekey = os.getenv("ImageAPI") # Your imgbb API key from environment variables
12
- IMGBB_API_KEY = imagekey
13
 
14
  def upload_image_to_imgbb(image_path):
15
  """Uploads an image to imgbb and returns the URL."""
16
- url = f"https://api.imgbb.com/1/upload?key={IMGBB_API_KEY}"
17
  with open(image_path, "rb") as image_file:
18
  files = {"image": image_file.read()}
19
  response = requests.post(url, files=files)
@@ -23,7 +24,7 @@ def upload_image_to_imgbb(image_path):
23
  raise ValueError(f"Image upload failed: {response.json()}")
24
 
25
  def analyze_image(image, instruction):
26
- """Analyzes the image using Groq's Llama 3.2 based on the instruction provided."""
27
  try:
28
  # Save the uploaded image locally
29
  image_path = "uploaded_image.png"
@@ -35,22 +36,20 @@ def analyze_image(image, instruction):
35
  # Debug: Log the uploaded image URL
36
  print(f"Uploaded Image URL: {image_url}")
37
 
38
- # Call the Groq API to analyze the image
39
- # Call the Groq API to analyze the image
40
- completion = client.chat.completions.create(
41
- model="llama-3.2-90b-vision-preview",
42
- messages=[{
43
- "role": "user",
44
- "content": [
45
- {"type": "text", "text": instruction},
46
- {"type": "image_url", "image_url": {"url": image_url}}
47
- ]
48
- }],
49
- temperature=0.7,
50
- max_tokens=512,
51
- top_p=1,
52
- stream=False,
53
- stop=None,
54
  )
55
 
56
  # Extract and return the response
@@ -77,4 +76,4 @@ iface = gr.Interface(
77
  )
78
 
79
  # Launch the app
80
- iface.launch()
 
1
  import os
2
  import gradio as gr
3
  import requests
4
+ import openai
5
+ from PIL import Image
6
 
7
+ # Set your API keys (replace with your actual keys or environment variables)
8
+ sambanova_api_key = os.getenv("Vision") # Sambanova API Key
9
+ imagebb_api_key = os.getenv("ImageAPI") # Your imgbb API key from environment variables
10
 
11
+ # Initialize Sambanova OpenAI client
12
+ openai.api_key = sambanova_api_key
13
+ openai.api_base = "https://api.sambanova.ai/v1"
14
 
15
  def upload_image_to_imgbb(image_path):
16
  """Uploads an image to imgbb and returns the URL."""
17
+ url = f"https://api.imgbb.com/1/upload?key={imagebb_api_key}"
18
  with open(image_path, "rb") as image_file:
19
  files = {"image": image_file.read()}
20
  response = requests.post(url, files=files)
 
24
  raise ValueError(f"Image upload failed: {response.json()}")
25
 
26
  def analyze_image(image, instruction):
27
+ """Analyzes the image using Sambanova's Llama 3.2 Vision Instruct based on the provided instruction."""
28
  try:
29
  # Save the uploaded image locally
30
  image_path = "uploaded_image.png"
 
36
  # Debug: Log the uploaded image URL
37
  print(f"Uploaded Image URL: {image_url}")
38
 
39
+ # Call the Sambanova API to analyze the image
40
+ completion = openai.ChatCompletion.create(
41
+ model="Llama-3.2-90B-Vision-Instruct",
42
+ messages=[
43
+ {
44
+ "role": "user",
45
+ "content": [
46
+ {"type": "text", "text": instruction},
47
+ {"type": "image_url", "image_url": {"url": image_url}}
48
+ ]
49
+ }
50
+ ],
51
+ temperature=0.1,
52
+ top_p=0.1,
 
 
53
  )
54
 
55
  # Extract and return the response
 
76
  )
77
 
78
  # Launch the app
79
+ iface.launch()