Update tools.py
Browse files
tools.py
CHANGED
|
@@ -20,47 +20,6 @@ def get_hub_stats(author: str) -> str:
|
|
| 20 |
return f"Error fetching models for {author}: {str(e)}"
|
| 21 |
|
| 22 |
|
| 23 |
-
# def analyze_image(image_path: str, question: str = "What do you see in this image?") -> str:
|
| 24 |
-
# """Analyze an image using LangChain's ChatOpenAI with vision"""
|
| 25 |
-
|
| 26 |
-
# def encode_image_to_base64(image_path: str) -> str:
|
| 27 |
-
# """Convert image file to base64 string"""
|
| 28 |
-
# try:
|
| 29 |
-
# with open(image_path, "rb") as image_file:
|
| 30 |
-
# return base64.b64encode(image_file.read()).decode('utf-8')
|
| 31 |
-
# except Exception as e:
|
| 32 |
-
# raise Exception(f"Error encoding image: {e}")
|
| 33 |
-
|
| 34 |
-
# try:
|
| 35 |
-
# # Create vision-capable LLM
|
| 36 |
-
# # vision_llm = ChatOpenAI(model="gpt-4o", max_tokens=1000)
|
| 37 |
-
# vision_llm = ChatOpenAI(model="gpt-4.1", max_tokens=1000)
|
| 38 |
-
|
| 39 |
-
# # Encode the image
|
| 40 |
-
# base64_image = encode_image_to_base64(image_path)
|
| 41 |
-
|
| 42 |
-
# # Create message with image
|
| 43 |
-
# message = HumanMessage(
|
| 44 |
-
# content=[
|
| 45 |
-
# {"type": "text", "text": question},
|
| 46 |
-
# {
|
| 47 |
-
# "type": "image_url",
|
| 48 |
-
# "image_url": {
|
| 49 |
-
# "url": f"data:image/jpeg;base64,{base64_image}",
|
| 50 |
-
# "detail": "high"
|
| 51 |
-
# }
|
| 52 |
-
# }
|
| 53 |
-
# ]
|
| 54 |
-
# )
|
| 55 |
-
|
| 56 |
-
# # Get response
|
| 57 |
-
# response = vision_llm.invoke([message])
|
| 58 |
-
# return response.content
|
| 59 |
-
|
| 60 |
-
# except Exception as e:
|
| 61 |
-
# return f"Error analyzing image: {e}"
|
| 62 |
-
|
| 63 |
-
|
| 64 |
def get_image_mime_type(image_path: str) -> str:
|
| 65 |
"""Detect the MIME type of an image file"""
|
| 66 |
import os
|
|
|
|
| 20 |
return f"Error fetching models for {author}: {str(e)}"
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def get_image_mime_type(image_path: str) -> str:
|
| 24 |
"""Detect the MIME type of an image file"""
|
| 25 |
import os
|