Update llm.py
Browse files
llm.py
CHANGED
@@ -1,20 +1,46 @@
|
|
1 |
import pytesseract
|
|
|
|
|
2 |
|
|
|
|
|
3 |
import google.generativeai as palm
|
4 |
-
api_key =
|
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
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
text = palm.generate_text(
|
15 |
-
prompt=prompt,
|
16 |
model=model,
|
17 |
-
temperature=0.
|
18 |
max_output_tokens=2000,
|
19 |
top_p=0.8,
|
20 |
top_k=40,
|
|
|
1 |
import pytesseract
|
2 |
+
import os
|
3 |
+
from dotenv import load_dotenv, find_dotenv
|
4 |
|
5 |
+
# LOAD THE API KEY FROM .env
|
6 |
+
load_dotenv(find_dotenv())
|
7 |
import google.generativeai as palm
|
8 |
+
api_key = os.environ["GOOGLE_API_KEY"] # put your API key here
|
9 |
palm.configure(api_key=api_key)
|
10 |
+
|
11 |
models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
|
12 |
+
|
13 |
+
|
14 |
+
def modelinfo():
|
15 |
+
model = [ model for model in palm.list_models() ]
|
16 |
+
for m in model:
|
17 |
+
print(f" Model Name: {m.name} \n
|
18 |
+
Display Name: {m.display_name} \n
|
19 |
+
Token Limit: {m.input_token_limit} , {m.output_token_limit} \n
|
20 |
+
Temperature: {m.temperature} \n")
|
21 |
+
|
22 |
model = models[0].name
|
23 |
|
24 |
def llm(img):
|
25 |
text = pytesseract.image_to_string(img, lang='eng')
|
26 |
# generate text
|
27 |
+
prompt = {"take this piece of information and give all the information in point wise better format also give some recommendation related to them, \
|
28 |
+
if you don't get any nutrition content simply reply 'I don't seem to have any knowledge of the particular Nutrition Content' " + text,
|
29 |
+
|
30 |
+
"Take this Nutrition facts information and give all the contents and proportion in point wise Markdown format also give some recommendation related to them, \
|
31 |
+
Make sure the Recommendations are given in bulleted format under the heading Recommendations \
|
32 |
+
if you don't get any nutrition content simply reply 'I don't seem to have any knowledge of the particular Nutrition Content' " + text,
|
33 |
+
|
34 |
+
"I've given you this piece of information it contains Nutrition facts, and I want you to give all the information in point-wise Markdown format also give some \
|
35 |
+
recommendation related to them like how the consumption of the content may affect your health and what kind of people will be benefited or harmed from a particular, \
|
36 |
+
content and its percentage if you don't get any nutrition content simply reply 'I don't seem to have any knowledge of the particular Nutrition Content' " + text
|
37 |
+
}
|
38 |
+
|
39 |
+
|
40 |
text = palm.generate_text(
|
41 |
+
prompt=prompt[0],
|
42 |
model=model,
|
43 |
+
temperature=0.3,
|
44 |
max_output_tokens=2000,
|
45 |
top_p=0.8,
|
46 |
top_k=40,
|