Upload 3 files
Browse files- app.py +18 -0
- llm.py +22 -0
- requirements.txt +5 -0
app.py
CHANGED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
from llm import llm
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def process_image(image):
|
7 |
+
# Convert Gradio Image to OpenCV format
|
8 |
+
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
9 |
+
|
10 |
+
# Perform your image processing
|
11 |
+
result = llm(img)
|
12 |
+
|
13 |
+
return result
|
14 |
+
|
15 |
+
iface = gr.Interface(fn=process_image, inputs="image", outputs=gr.Markdown(), live=True, title="Nutrition Content Based LLM", description="The llm based project needs a clear image of only the Nutrition Facts Box at the back of a product, \n The llm shows the content and give health advice based on the Nutritions Facts.")
|
16 |
+
|
17 |
+
|
18 |
+
iface.launch()
|
llm.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytesseract
|
2 |
+
|
3 |
+
import google.generativeai as palm
|
4 |
+
api_key = 'AIzaSyB7-RzBwTAfVA-7ZGk2mEOQwOxshpwzhpM' # put your API key here
|
5 |
+
palm.configure(api_key=api_key)
|
6 |
+
models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
|
7 |
+
model = models[0].name
|
8 |
+
|
9 |
+
def llm(img):
|
10 |
+
text = pytesseract.image_to_string(img, lang='eng')
|
11 |
+
# generate text
|
12 |
+
prompt = "take this peace of information and give all the information in point wise better format also give some recomendation related to them, if you don't get any nutrition content simply reply 'I don't seem have any knowledge of the perticular Nutrition Content' " + text
|
13 |
+
# print(prompt)
|
14 |
+
text = palm.generate_text(
|
15 |
+
prompt=prompt,
|
16 |
+
model=model,
|
17 |
+
temperature=0.3,
|
18 |
+
max_output_tokens=2000,
|
19 |
+
top_p=0.8,
|
20 |
+
top_k=40,
|
21 |
+
)
|
22 |
+
return text.result
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pytesseract
|
2 |
+
streamlit
|
3 |
+
numpy
|
4 |
+
google-generativeai
|
5 |
+
opencv-python
|