gamingflexer commited on
Commit
34819e5
·
1 Parent(s): 1c114a1

Debug changes for deployment

Browse files
src/app/api/module/audio_text.py CHANGED
@@ -34,16 +34,10 @@ def whisper_pipeline(audio_path):
34
  print(result.text)
35
  return result.text
36
 
37
-
38
-
39
-
40
-
41
  def whisper_openai(audio_path):
42
  audio_file= open(audio_path, "rb")
43
  transcript = client.audio.transcriptions.create(
44
  model="whisper-1",
45
  file=audio_file
46
  )
47
- return transcript
48
-
49
- whisper_pipeline()
 
34
  print(result.text)
35
  return result.text
36
 
 
 
 
 
37
  def whisper_openai(audio_path):
38
  audio_file= open(audio_path, "rb")
39
  transcript = client.audio.transcriptions.create(
40
  model="whisper-1",
41
  file=audio_file
42
  )
43
+ return transcript
 
 
src/app/api/module/product_description.py CHANGED
@@ -1,42 +1,30 @@
1
- import cv2
2
- import os
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
- from llm_vision import OpenAIVision
6
- from ocr import azure_ocr
7
- from prompts.base import base_prompt, gpt3
8
- from utils import extract_json_from_text
9
- from vectorsearch import search , get_detail_df
10
  import json
11
 
12
- def get_details(image_path , details): ### If product is not in database
 
13
  prompt = base_prompt.format(text = details)
 
14
  obj = OpenAIVision()
15
  jsontext = obj.get_image_description(image_path,prompt)
16
  response = extract_json_from_text(jsontext['choices'][0]['message']['content'])
17
- ##add
18
  return response
19
 
20
- def get_name(image_path): ### If product is in database
21
  details = azure_ocr(image_path)
22
  prompt = gpt3.format(text = details)
23
  obj = OpenAIVision()
24
  name = obj.getname(prompt)
25
  jsontext = json.loads(name.content)
26
  print(jsontext)
27
- product_name = jsontext['product_name']
28
- get_prod_name_db = search(product_name)
29
  # if name not in db:
30
  # response = get_details(image_path, details)
31
  # add_in_db(response)
32
  # else:
33
  # add_in_db(get_prod_name_db)
34
-
35
-
36
- def add_in_db(response):
37
- pass
38
-
39
-
40
- if __name__ == "__main__":
41
- image_path = r"data/remove_flash.jpg"
42
- get_name(image_path)
 
1
+ from api.module.llm_vision import OpenAIVision
2
+ from api.module.ocr import azure_ocr
3
+ from api.module.prompts.base import base_prompt, gpt3
4
+ from api.module.utils import extract_json_from_text
5
+ # from vectorsearch import search , get_detail_df
 
 
 
 
6
  import json
7
 
8
+ def get_details(image_path):
9
+ details = azure_ocr(image_path)
10
  prompt = base_prompt.format(text = details)
11
+ # print(prompt)
12
  obj = OpenAIVision()
13
  jsontext = obj.get_image_description(image_path,prompt)
14
  response = extract_json_from_text(jsontext['choices'][0]['message']['content'])
 
15
  return response
16
 
17
+ def get_name(image_path):
18
  details = azure_ocr(image_path)
19
  prompt = gpt3.format(text = details)
20
  obj = OpenAIVision()
21
  name = obj.getname(prompt)
22
  jsontext = json.loads(name.content)
23
  print(jsontext)
24
+ # product_name = jsontext['product_name']
25
+ # get_prod_name_db = search(product_name)
26
  # if name not in db:
27
  # response = get_details(image_path, details)
28
  # add_in_db(response)
29
  # else:
30
  # add_in_db(get_prod_name_db)
 
 
 
 
 
 
 
 
 
src/app/api/views.py CHANGED
@@ -6,12 +6,12 @@ from django.shortcuts import render, get_object_or_404
6
  from rest_framework.views import APIView
7
  from rest_framework.response import Response
8
  from rest_framework import status
9
- from .models import Product,Record
10
- from django.contrib import messages
11
  from .serializers import ProductSerializer
12
  from django.http import JsonResponse
13
  import os
14
  from config import BASE_PATH
 
15
 
16
  def catalouge_page(request):
17
  # Fetch all products from the database
@@ -84,19 +84,27 @@ def upload_image_and_audio(request):
84
  for image in images:
85
  # Save the image locally in the static directory
86
  image_name = image.name
87
- image_path = os.path.join(BASE_PATH,'app','main',settings.STATIC_ROOT, 'images', image_name)
88
  with open(image_path, 'wb') as f:
89
  for chunk in image.chunks():
90
  f.write(chunk)
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- product_details = []
93
- dummy_data = [
94
- {'barcode': '123456', 'brand': 'Brand A', 'manufactured_by': 'Manufacturer A', 'product_name': 'Product A', 'weight': 1.5, 'variant': 'Variant A', 'net_content': '100ml', 'price': 10.0, 'parent_category': 'Category A', 'child_category': 'Subcategory A', 'description': 'Description for Product A', 'quantity': 100, 'mrp': '20.0'},
95
- {'barcode': '654321', 'brand': 'Brand B', 'manufactured_by': 'Manufacturer B', 'product_name': 'Product B', 'weight': 2.0, 'variant': 'Variant B', 'net_content': '200ml', 'price': 15.0, 'parent_category': 'Category B', 'child_category': 'Subcategory B', 'description': 'Description for Product B', 'quantity': 200, 'mrp': '25.0'}
96
- ]
97
- # product = Product.objects.create(data)
98
- product_details.extend(dummy_data)
99
- return JsonResponse(dummy_data[0], safe=False) # Return product details as JSON response
100
  return render(request, 'upload_image.html')
101
 
102
  class ProductAPIView(APIView):
 
6
  from rest_framework.views import APIView
7
  from rest_framework.response import Response
8
  from rest_framework import status
9
+ from .models import Product
 
10
  from .serializers import ProductSerializer
11
  from django.http import JsonResponse
12
  import os
13
  from config import BASE_PATH
14
+ from api.module.product_description import get_details
15
 
16
  def catalouge_page(request):
17
  # Fetch all products from the database
 
84
  for image in images:
85
  # Save the image locally in the static directory
86
  image_name = image.name
87
+ image_path = os.path.join(BASE_PATH,'app','main',settings.MEDIA_ROOT, 'images', image_name)
88
  with open(image_path, 'wb') as f:
89
  for chunk in image.chunks():
90
  f.write(chunk)
91
+ print('Image saved at:', image_path)
92
+ input_data = get_details(image_path)
93
+ static_img_path = "http://34.122.223.224:9002/media/images/" + image_name
94
+ product_data = {
95
+ 'brand': input_data.get('brand',None),
96
+ 'mrp': input_data.get('mrp',None),
97
+ 'quantity': input_data.get('quantity',None),
98
+ 'parent_category': input_data.get('parent_category',None),
99
+ 'manufactured_by': input_data.get('manufactured_by', ''),
100
+ 'product_name': input_data.get('type_of_product',None),
101
+ 'images_paths': static_img_path, # Static path after saving image
102
+ 'description': input_data.get('description',None)
103
+ }
104
 
105
+ # Create a new Product instance and save to database
106
+ product = Product.objects.create(**product_data)
107
+ return JsonResponse(product_data, safe=False) # Return product details as JSON response
 
 
 
 
 
108
  return render(request, 'upload_image.html')
109
 
110
  class ProductAPIView(APIView):
src/app/main/urls.py CHANGED
@@ -1,8 +1,12 @@
1
  from django.contrib import admin
2
  from django.urls import path
3
  from django.urls import include
 
 
4
 
5
  urlpatterns = [
6
  path('admin/', admin.site.urls),
7
  path('', include('api.urls')),
8
- ]
 
 
 
1
  from django.contrib import admin
2
  from django.urls import path
3
  from django.urls import include
4
+ from django.conf import settings
5
+ from django.conf.urls.static import static
6
 
7
  urlpatterns = [
8
  path('admin/', admin.site.urls),
9
  path('', include('api.urls')),
10
+ ]
11
+ if settings.DEBUG:
12
+ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)