Commit
·
adae09f
0
Parent(s):
Init clean HF space
Browse files- .gitattributes +35 -0
- README.md +12 -0
- app.py +93 -0
- requirements.txt +6 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: GetReg
|
| 3 |
+
emoji: 🐢
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.38.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
import os
|
| 3 |
+
import google.generativeai as genai
|
| 4 |
+
from groq import Groq
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import requests
|
| 8 |
+
from io import BytesIO
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# Load environment variables from .env
|
| 12 |
+
load_dotenv()
|
| 13 |
+
|
| 14 |
+
from groq import Groq
|
| 15 |
+
|
| 16 |
+
client = Groq(
|
| 17 |
+
api_key=os.environ.get("GROQ_API_KEY"),
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Fetch variables
|
| 24 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
#login(token=HF_TOKEN)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def product_identification_response(image_path=r"C:\Users\JoeJo\Downloads\XyAaqBEtYtb8YffjKZ68Gb.jpg"):
|
| 31 |
+
# Authenticate
|
| 32 |
+
genai.configure(api_key=os.environ.get("GENAI_API_KEY"))
|
| 33 |
+
|
| 34 |
+
# Load Gemini Pro Vision
|
| 35 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 36 |
+
|
| 37 |
+
# Load your image
|
| 38 |
+
clean_path = image_path.strip('"')
|
| 39 |
+
#image = Image.open(clean_path)
|
| 40 |
+
|
| 41 |
+
if clean_path.startswith("http"):
|
| 42 |
+
response = requests.get(clean_path)
|
| 43 |
+
response.raise_for_status() # Throw error if download fails
|
| 44 |
+
image = Image.open(BytesIO(response.content))
|
| 45 |
+
else:
|
| 46 |
+
image = Image.open(clean_path)
|
| 47 |
+
|
| 48 |
+
# Ask Gemini
|
| 49 |
+
response = model.generate_content(
|
| 50 |
+
["What is the registration number of the vehicle in this image", image]
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
print(f"gemini-1.5-flash answer is: {response.text}")
|
| 54 |
+
|
| 55 |
+
prompt = f"""Your task is to returned structured JSON of product and condition in the following format: {{ "product": "the identity of the product", "condition": "the condition of the product"}}.
|
| 56 |
+
The condition of the product must be one of the following: (*) New, (*) Like New, (*) Good or (*) Poor.
|
| 57 |
+
Use the data from {response} as the source for your response
|
| 58 |
+
"""
|
| 59 |
+
prompt2 = f"""Your task is to returned structured JSON of the registration of the car in the image, in the following format: {{ "registration_number": "the registration number of the car" }}.
|
| 60 |
+
The registration number is the two art number that is visible at the front of the car.
|
| 61 |
+
Use this image of the car as your data source: {response}"""
|
| 62 |
+
|
| 63 |
+
chat_completion = client.chat.completions.create(
|
| 64 |
+
messages=[
|
| 65 |
+
{
|
| 66 |
+
"role": "system",
|
| 67 |
+
"content": prompt2
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"role": "user",
|
| 71 |
+
"content": response.text,
|
| 72 |
+
}
|
| 73 |
+
],
|
| 74 |
+
model="llama-3.3-70b-versatile",
|
| 75 |
+
response_format={"type": "json_object"},#and include word 'json' in messages/prompt
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
print(chat_completion.choices[0].message.content)
|
| 79 |
+
return chat_completion.choices[0].message.content
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
#product_identification_response()
|
| 84 |
+
|
| 85 |
+
demo = gr.Interface(
|
| 86 |
+
fn=product_identification_response,
|
| 87 |
+
inputs="text",
|
| 88 |
+
outputs="text",
|
| 89 |
+
title="identify registration number",
|
| 90 |
+
description="finds info about a product"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python-dotenv
|
| 2 |
+
google-generativeai
|
| 3 |
+
groq
|
| 4 |
+
Pillow
|
| 5 |
+
gradio
|
| 6 |
+
requests
|