Spaces:
Runtime error
Runtime error
Commit
·
8717c3c
1
Parent(s):
f6e26d0
testing
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/app.cpython-312.pyc +0 -0
- app.py +86 -4
- requirements.txt +2 -1
__pycache__/app.cpython-310.pyc
CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
__pycache__/app.cpython-312.pyc
ADDED
Binary file (2.76 kB). View file
|
|
app.py
CHANGED
@@ -1,6 +1,68 @@
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
custom_css = """
|
6 |
.big-font textarea {
|
@@ -8,10 +70,30 @@ custom_css = """
|
|
8 |
}
|
9 |
"""
|
10 |
|
11 |
-
def extract_text(
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Create the Gradio interface
|
17 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
import pytesseract
|
4 |
+
import json
|
5 |
+
|
6 |
+
import google.generativeai as genai
|
7 |
+
google_api = 'AIzaSyAMlYqwvuQgekl8nlqc56XTqJVBufszrBU'
|
8 |
+
genai.configure(api_key=google_api)
|
9 |
+
from pathlib import Path
|
10 |
+
from IPython.display import Markdown
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
from PIL import Image
|
16 |
+
import io
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
# Model Configuration
|
22 |
+
MODEL_CONFIG = {
|
23 |
+
"temperature": 0.2,
|
24 |
+
"top_p": 1,
|
25 |
+
"top_k": 32,
|
26 |
+
"max_output_tokens": 4096,
|
27 |
+
}
|
28 |
+
|
29 |
+
## Safety Settings of Model
|
30 |
+
safety_settings = [
|
31 |
+
{
|
32 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
33 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
34 |
+
},
|
35 |
+
{
|
36 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
37 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
41 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
45 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
46 |
+
}
|
47 |
+
]
|
48 |
+
|
49 |
+
model = genai.GenerativeModel(model_name='gemini-2.5-flash',
|
50 |
+
generation_config=MODEL_CONFIG,
|
51 |
+
safety_settings=safety_settings)
|
52 |
+
|
53 |
+
|
54 |
+
def gemini_output(image_path,
|
55 |
+
system_prompt,
|
56 |
+
user_prompt):
|
57 |
+
|
58 |
+
|
59 |
+
input_prompt = [system_prompt, image_path, user_prompt]
|
60 |
+
response = model.generate_content(input_prompt)
|
61 |
+
|
62 |
+
return response.text
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
|
67 |
custom_css = """
|
68 |
.big-font textarea {
|
|
|
70 |
}
|
71 |
"""
|
72 |
|
73 |
+
def extract_text(image_path):
|
74 |
+
|
75 |
+
system_prompt = """
|
76 |
+
You are a specialist in comprehending receipts.
|
77 |
+
Input images in the form of receipts will be provided to you,
|
78 |
+
and your task is to respond to questions based on the content of the input image.
|
79 |
+
"""
|
80 |
+
|
81 |
+
user_prompt = "Convert Invoice data into json format with appropriate json tags as required for the data in image "
|
82 |
+
output = gemini_output(image_path, system_prompt, user_prompt)
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
output = output.replace("```json", "")
|
87 |
+
output = output.replace("```", "")
|
88 |
+
|
89 |
+
|
90 |
+
print(f">>>>>>> {output}")
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
return output
|
96 |
+
|
97 |
|
98 |
# Create the Gradio interface
|
99 |
iface = gr.Interface(
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
pytesseract
|
2 |
pillow
|
3 |
-
gradio
|
|
|
|
1 |
pytesseract
|
2 |
pillow
|
3 |
+
gradio
|
4 |
+
google-generativeai
|