JustKiddo commited on
Commit
236623a
·
verified ·
1 Parent(s): 34ed9b9

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -76
app.py DELETED
@@ -1,76 +0,0 @@
1
- import gradio as gr
2
- import numpy as np
3
- #from transformers import TrOCRProcessor, VisionEncoderDecoderModel
4
- from transformers import AutoProcessor, AutoModelForDocumentQuestionAnswering
5
- from PIL import Image
6
-
7
- #client = InferenceClient("models/microsoft/trocr-base-handwritten")
8
- processor = AutoProcessor.from_pretrained("Sharka/CIVQA_LayoutLMv2_EasyOCR")
9
- model = AutoModelForDocumentQuestionAnswering.from_pretrained("Sharka/CIVQA_LayoutLMv2_EasyOCR")
10
-
11
- def sepia(input_img):
12
- sepia_filter = np.array([
13
- [0.393, 0.769, 0.189],
14
- [0.349, 0.686, 0.168],
15
- [0.272, 0.534, 0.131]
16
- ])
17
- sepia_img = input_img.dot(sepia_filter.T)
18
- sepia_img /= sepia_img.max()
19
- sepia_values = repr(sepia_img)
20
- return sepia_img, sepia_values
21
-
22
-
23
- ## https://www.gradio.app/docs/gradio/blocks
24
- ## required positional arguments: 'inputs' and 'outputs'
25
- def process_image(image):
26
- try:
27
- pixel_values = processor(images=image, return_tensors="pt").pixel_values
28
-
29
- generated_ids = model.generate(pixel_values)
30
- generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
31
- return generated_text
32
- except Exception as e:
33
- return f"Error: {str(e)}"
34
-
35
- def additional_input(text):
36
- return f"Additional input received: {text}"
37
-
38
- sepia_interface = gr.Interface(sepia, gr.Image(), "image")
39
-
40
- with gr.Blocks() as generated_output:
41
- with gr.Column():
42
- sepia_values_text=gr.Textbox(label="Sepia Values")
43
- output_img = gr.Image(label="Output Image")
44
- gr.Interface(fn=sepia,
45
- inputs=gr.Image(
46
- #this makes the camera stream live
47
- sources=["webcam"],
48
- streaming=True
49
- ),
50
- outputs=[output_img, sepia_values_text],
51
- live=True,
52
- show_progress="full")
53
- with gr.Row():
54
- output_img.change(
55
- fn=process_image,
56
- inputs=output_img,
57
- outputs=gr.Textbox(label="Recognized Text"),
58
- show_progress="full")
59
- #with gr.Blocks() as generated_output:
60
- # inp = gr.Interface(sepia, gr.Image(), "image")
61
- # out = gr.Textbox()
62
-
63
-
64
- #demo = gr.TabbedInterface([sepia_interface, generated_output], ["RGB Sepia Filter", "Handwritten to Text"])
65
-
66
- #with gr.Blocks() as demo:
67
- # with gr.Row():
68
- # input_img = gr.Image(label="Input Image")
69
- # submit_button = gr.Button("Submit")
70
- # output_img = gr.Image(label="Output Image")
71
- # sepia_values_text = gr.Textbox(label="Sepia Values")
72
-
73
- # submit_button.click(sepia, inputs=input_img, outputs=[output_img, sepia_values_text])
74
-
75
- if __name__ == "__main__":
76
- generated_output.launch()