Spaces:
Runtime error
Runtime error
tc-ha
commited on
Commit
•
51dfab7
1
Parent(s):
472c73d
add requirement
Browse files
app.py
CHANGED
@@ -1,117 +1,122 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
config = Config()
|
31 |
|
32 |
-
def predict_start_first(outputs):
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
|
56 |
-
|
57 |
|
58 |
-
# Define function to make predictions
|
59 |
-
def predict(config, model, image, question):
|
60 |
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
|
74 |
|
75 |
-
|
76 |
|
77 |
-
|
78 |
|
79 |
-
def main(config):
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
|
109 |
-
|
110 |
|
111 |
|
112 |
-
if __name__ == '__main__':
|
113 |
-
|
114 |
-
|
115 |
|
116 |
|
117 |
|
|
|
1 |
import streamlit as st
|
2 |
+
|
3 |
+
x = st.slider('Select a value')
|
4 |
+
st.write(x, 'squared is', x * x)
|
5 |
+
|
6 |
+
# import streamlit as st
|
7 |
+
# import torch
|
8 |
+
# from PIL import Image
|
9 |
+
# import json
|
10 |
+
# from tqdm import tqdm
|
11 |
+
|
12 |
+
# from transformers import AutoModelForQuestionAnswering, LayoutLMv2Processor, AutoTokenizer
|
13 |
+
|
14 |
+
# class Config():
|
15 |
+
# def __init__(self):
|
16 |
+
# self.data_dir = "/opt/ml/input/data/"
|
17 |
+
# self.model = "layoutlmv2"
|
18 |
+
# self.device = "cpu"
|
19 |
+
# self.checkpoint = "microsoft/layoutlmv2-base-uncased"
|
20 |
+
# self.use_ocr_library = False
|
21 |
+
# self.debug = False
|
22 |
+
# self.batch_data = 1
|
23 |
+
# self.num_proc = 1
|
24 |
+
# self.shuffle = True
|
25 |
|
26 |
+
# self.lr = 5e-6
|
27 |
+
# self.seed = 42
|
28 |
+
# self.batch = 1
|
29 |
+
# self.max_len = 512
|
30 |
+
# self.epochs = 1000
|
31 |
|
32 |
+
# self.fuzzy = False
|
33 |
+
# self.model_name = ''
|
34 |
|
35 |
+
# config = Config()
|
36 |
|
37 |
+
# def predict_start_first(outputs):
|
38 |
+
# start_logits = outputs.start_logits
|
39 |
+
# end_logits = outputs.end_logits
|
40 |
|
41 |
+
# predicted_start_idx_list = []
|
42 |
+
# predicted_end_idx_list = []
|
43 |
|
44 |
+
# start_position = start_logits.argmax(1)
|
45 |
|
46 |
+
# for i in range(len(start_logits)):
|
47 |
|
48 |
+
# start = start_position[i]
|
49 |
+
# predicted_start_idx_list.append(start)
|
50 |
+
# max_score = -float('inf')
|
51 |
+
# predicted_end_idx = 0
|
52 |
|
53 |
+
# for end in range(start, len(end_logits[i])):
|
54 |
+
# score = end_logits[i][end]
|
55 |
+
# if score > max_score:
|
56 |
+
# max_score = score
|
57 |
+
# predicted_end_idx = end
|
58 |
|
59 |
+
# predicted_end_idx_list.append(predicted_end_idx)
|
60 |
|
61 |
+
# return predicted_start_idx_list, predicted_end_idx_list
|
62 |
|
63 |
+
# # Define function to make predictions
|
64 |
+
# def predict(config, model, image, question):
|
65 |
|
66 |
+
# processor = LayoutLMv2Processor.from_pretrained("microsoft/layoutlmv2-base-uncased")
|
67 |
+
# encoding = processor(image, question, return_tensors="pt")
|
68 |
|
69 |
+
# # model
|
70 |
+
# with torch.no_grad():
|
71 |
+
# output = model(
|
72 |
+
# input_ids=encoding['input_ids'],
|
73 |
+
# attention_mask=encoding['attention_mask'],
|
74 |
+
# token_type_ids=encoding['token_type_ids'],
|
75 |
+
# bbox=encoding['bbox'], image=encoding['image']
|
76 |
+
# )
|
77 |
|
78 |
+
# predicted_start_idx, predicted_end_idx = predict_start_first(output)
|
79 |
|
80 |
+
# answer = processor.tokenizer.decode(encoding['input_ids'][0, predicted_start_idx[0]:predicted_end_idx[0]+1])
|
81 |
|
82 |
+
# return answer
|
83 |
|
84 |
+
# def main(config):
|
85 |
|
86 |
+
# # Load deep learning model
|
87 |
+
# checkpoint = ''
|
88 |
+
# model = AutoModelForQuestionAnswering.from_pretrained('microsoft/layoutlmv2-base-uncased').to(config.device)
|
89 |
+
# # model.load_state_dict(torch.load("model"))
|
90 |
|
91 |
+
# # Create Streamlit app
|
92 |
+
# st.title('Deep Learning Pipeline')
|
93 |
+
# st.write('Upload an image and ask a question to get a prediction')
|
94 |
|
95 |
+
# # Create file uploader and text input widgets
|
96 |
+
# uploaded_file = st.file_uploader("Choose an image", type=['jpg', 'jpeg', 'png'])
|
97 |
+
# question = st.text_input('Ask a question')
|
98 |
|
99 |
+
# # If file is uploaded, show the image
|
100 |
+
# if uploaded_file is not None:
|
101 |
+
# image = Image.open(uploaded_file).convert("RGB")
|
102 |
+
# st.image(image, caption='Uploaded Image', use_column_width=True)
|
103 |
|
104 |
+
# # If question is asked and file is uploaded, make a prediction
|
105 |
+
# if st.button('Get Prediction') and uploaded_file is not None and question != '':
|
106 |
+
# # Preprocess the image and question as needed
|
107 |
+
# # ...
|
108 |
|
109 |
+
# # Make the prediction
|
110 |
+
# with st.spinner('Predicting...'):
|
111 |
+
# output = predict(config, model, image, question)
|
112 |
|
113 |
+
# # Show the output
|
114 |
+
# st.write('Output:', output)
|
115 |
|
116 |
|
117 |
+
# if __name__ == '__main__':
|
118 |
+
# config = Config()
|
119 |
+
# main(config)
|
120 |
|
121 |
|
122 |
|