martin8 commited on
Commit
90f0fb7
1 Parent(s): 1aa98ab

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +799 -0
app.py ADDED
@@ -0,0 +1,799 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import TextClassificationPipeline
2
+ from transformers import AutoTokenizer
3
+ from transformers import pipeline
4
+ import evaluate
5
+ import gradio as gr
6
+ import torch
7
+ import random
8
+ from transformers.file_utils import is_tf_available, is_torch_available, is_torch_tpu_available
9
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
10
+ from datasets import load_metric
11
+ from sklearn.model_selection import train_test_split
12
+ import pandas as pd
13
+ import numpy as np
14
+ import streamlit as st
15
+ from textblob import TextBlob
16
+ from streamlit_extras.switch_page_button import switch_page
17
+ from transformers import YolosImageProcessor, YolosForObjectDetection
18
+ from PIL import Image
19
+ import torch
20
+ import requests
21
+ import numpy as np
22
+ import torchvision
23
+ from torchvision.io import read_image
24
+ from torchvision.utils import draw_bounding_boxes
25
+ from transformers import DetrImageProcessor, DetrForObjectDetection
26
+ from transformers import DetrImageProcessor, DetrForObjectDetection
27
+ from transformers import pipeline
28
+ import torch
29
+ from transformers import PegasusForConditionalGeneration, PegasusTokenizer
30
+
31
+
32
+ st.set_page_config(layout="wide")
33
+ def get_models(prompt):
34
+ #prompt = input("Enter your AI task idea:")
35
+ response = pipe(prompt)
36
+ print("AI Model Idea: ", prompt,"\n")
37
+
38
+ x = pd.json_normalize(response[0])
39
+ # x.nlargest(3,['score'])["label"].values
40
+ knowledge_base_tasks = ['depth-estimation', 'image-classification', 'image-segmentation',
41
+ 'image-to-image', 'object-detection', 'video-classification',
42
+ 'unconditional-image-generation', 'zero-shot-image-classification',
43
+ 'conversational', 'fill-mask', 'question-answering',
44
+ 'sentence-similarity', 'summarization', 'table-question-answering',
45
+ 'text-classification', 'text-generation', 'token-classification',
46
+ 'translation', 'zero-shot-classification']
47
+
48
+ temp = []
49
+ for label_code in x.nlargest(3,['score'])["label"].values:
50
+ temp.append(label_code[6:])
51
+ # temp
52
+
53
+ cat_to_model = {}
54
+ top_cats = []
55
+
56
+ for i in range(len(temp)):
57
+ print("Possible Category ",i+1," : ",knowledge_base_tasks[int(temp[i])])
58
+ print("Top three models for this category are:",models_list[models_list["pipeline_tag"] == knowledge_base_tasks[int(temp[i])]].nlargest(3,"downloads")["modelId"].values)
59
+ cat_to_model[knowledge_base_tasks[int(temp[i])]] = models_list[models_list["pipeline_tag"] == knowledge_base_tasks[int(temp[i])]].nlargest(3,"downloads")["modelId"].values
60
+ top_cats.append(knowledge_base_tasks[int(temp[i])])
61
+ # models_list[models_list["pipeline_tag"] == "image-classification"].nlargest(3,"downloads")["modelId"].values
62
+ print()
63
+ print("Returning category-models dictionary..")
64
+ return top_cats,cat_to_model
65
+
66
+
67
+
68
+ def get_top_3(top_cat):
69
+
70
+ top_3_df = pd.read_csv("./Top_3_models.csv")
71
+ top_3 = []
72
+ for i in range(top_3_df.shape[0]):
73
+ if top_3_df["Category"].iloc[i].lower() == top_cat:
74
+ top_3.append(top_3_df["Model_1"].iloc[i])
75
+ top_3.append(top_3_df["Model_2"].iloc[i])
76
+ top_3.append(top_3_df["Model_3"].iloc[i])
77
+ break
78
+ return top_3
79
+
80
+
81
+
82
+
83
+
84
+ def get_top_3_a(prompt,pipe):
85
+ response = pipe(prompt)
86
+ x = pd.json_normalize(response[0])
87
+ temp = []
88
+ for label_code in x.nlargest(3,['score'])["label"].values:
89
+ temp.append(label_code[6:])
90
+ knowledge_base_tasks = ['depth-estimation', 'image-classification', 'image-segmentation',
91
+ 'image-to-image', 'object-detection', 'video-classification',
92
+ 'unconditional-image-generation', 'zero-shot-image-classification',
93
+ 'conversational', 'fill-mask', 'question-answering',
94
+ 'sentence-similarity', 'summarization', 'table-question-answering',
95
+ 'text-classification', 'text-generation', 'token-classification',
96
+ 'translation', 'zero-shot-classification']
97
+
98
+ top_cat = knowledge_base_tasks[int(temp[0])]
99
+
100
+
101
+ top_3_df = pd.read_csv("./Top_3_models.csv")
102
+ top_3 = []
103
+ for i in range(top_3_df.shape[0]):
104
+ if top_3_df["Category"].iloc[i] == top_cat:
105
+ top_3.append(top_3_df["Model_1"].iloc[i])
106
+ top_3.append(top_3_df["Model_2"].iloc[i])
107
+ top_3.append(top_3_df["Model_3"].iloc[i])
108
+ break
109
+ return top_cat,top_3
110
+
111
+
112
+
113
+
114
+ def get_response(input_text,model_name):
115
+ torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
116
+ tokenizer = PegasusTokenizer.from_pretrained(model_name)
117
+ model = PegasusForConditionalGeneration.from_pretrained(model_name).to(torch_device)
118
+ batch = tokenizer([input_text],truncation=True,padding='longest',max_length=1024, return_tensors="pt").to(torch_device)
119
+ gen_out = model.generate(**batch,max_length=128,num_beams=5, num_return_sequences=1, temperature=1.5)
120
+ output_text = tokenizer.batch_decode(gen_out, skip_special_tokens=True)
121
+ return output_text
122
+
123
+
124
+ def summarizer (models, data):
125
+ model_Eval = {}
126
+ for i in range (len(models)):
127
+ # print(models[i])
128
+ if models[i] == 'tuner007/pegasus_summarizer':
129
+ model_name = 'tuner007/pegasus_summarizer'
130
+
131
+ result = get_response(data,model_name)
132
+ rouge = evaluate.load('rouge')
133
+ # print("345",rouge.compute(predictions=[result],references=[data]))
134
+ print(type(result), type([data]))
135
+ quality = rouge.compute(predictions=[result[0]],references=[data])
136
+ model_Eval[models[i]] = {"Score":quality,"Result": result}
137
+ else:
138
+ summarizer_model = pipeline("summarization", model = models[i])
139
+ print(models[i], summarizer_model(data))
140
+ try:
141
+ result = summarizer_model(data)[0]["summary_text"]
142
+ rouge = evaluate.load('rouge')
143
+ # print("345",rouge.compute(predictions=[result],references=[data]))
144
+ quality = rouge.compute(predictions=[result],references=[data])
145
+ model_Eval[models[i]] = {"Score":quality,"Result": result}
146
+ except:
147
+ print("Model {} has issues.".format(models[i]))
148
+
149
+ return model_Eval
150
+
151
+
152
+
153
+
154
+ def best_model (analysis, data):
155
+ best_model_score = 0
156
+ best_model_name = ""
157
+ best_model_result = ""
158
+ temp2 = 0
159
+ for model in analysis.keys():
160
+ temp1 = analysis[model]["Score"]["rougeLsum"]
161
+ if temp1 > temp2:
162
+ temp2 = analysis[model]["Score"]["rougeLsum"]
163
+ best_model_score = analysis[model]["Score"]
164
+ best_model_name = model
165
+ best_model_result = analysis[model]["Result"]
166
+
167
+ return best_model_name, best_model_score,data[:50],best_model_result.replace("\n","")
168
+
169
+
170
+
171
+ def text_summarization():
172
+ top_models = get_top_3("summarization")
173
+ # st.write("Upload your file: ")
174
+ # uploaded_files = ""
175
+ # uploaded_files = st.file_uploader("Choose your file", accept_multiple_files=True)
176
+
177
+
178
+
179
+
180
+ option = st.selectbox(
181
+ 'What text would you like AI to summarize for you?',
182
+ ("Choose text files below:",'How to Win friends - Text', 'mocktext', '--')) #add 2 other options of files here
183
+
184
+ if option == 'How to Win friends - Text' or option == 'mocktext' or option == '--':### update book text files here
185
+ st.write('You selected:', option)
186
+
187
+ if option == 'How to Win friends - Text': # add text
188
+ name = "How_to_win_friends.txt"
189
+ st.write("Selected file for analyis is: How_to_win_friends.txt")
190
+
191
+ if option == 'mocktext':
192
+ name = "mocktext.txt"
193
+ st.write("Selected file for analyis is: mocktext.txt")
194
+
195
+ if option == '--':
196
+ name = "--"
197
+ st.write("--")
198
+
199
+
200
+
201
+ if st.button("Select"):
202
+ global file_data
203
+ # st.write("filename:", uploaded_files)
204
+ # for uploaded_file in uploaded_files:
205
+ # # print("here")
206
+ # file_data = open(uploaded_file.name,encoding="utf8").read()
207
+ # st.write("filename:", uploaded_file.name)
208
+ # # st.write(file_data[:500])
209
+ # # print("before summarizer")
210
+ # print(file_data[:50])
211
+ file_data = open(name,encoding="utf8").read()
212
+
213
+ analysis = summarizer(models = top_models, data = file_data[:500])
214
+
215
+ x,c,v,b = best_model(analysis,file_data[:500])
216
+ # st.write("Best model for Task: ",z)
217
+
218
+ st.markdown(f'<p style="color: #012d51;font-size:24px;border-radius:%;">{"Best Model with Summarization Results"}</p>', unsafe_allow_html=True)
219
+ st.write("\nBest model name: ",x)
220
+ # st.write("\nBest model Score: ",c)
221
+
222
+ st.write("Best Model Rouge Scores: ")
223
+ st.write("Rouge 1 Score: ",c["rouge1"])
224
+ st.write("Rouge 2 Score: ",c["rouge2"])
225
+ st.write("Rouge L Score: ",c["rougeL"])
226
+ st.write("Rouge LSum Score: ",c["rougeLsum"])
227
+
228
+ st.write("\nOriginal Data first 50 characters: ", v)
229
+ st.write("\nBest Model Result: ",b)
230
+
231
+
232
+ # print("between summarizer analysis")
233
+ st.markdown(f'<p style="color: #012d51;font-size:18px;border-radius:%;">{"Summarization Results for Model 1"}</p>', unsafe_allow_html=True)
234
+ # st.write("Summarization Results for Model 1")
235
+ st.write("Model name: facebook/bart-large-cnn")
236
+ st.write("Rouge Scores: ")
237
+ st.write("Rouge 1 Score: ",analysis["facebook/bart-large-cnn"]["Score"]["rouge1"])
238
+ st.write("Rouge 2 Score: ",analysis["facebook/bart-large-cnn"]["Score"]["rouge2"])
239
+ st.write("Rouge L Score: ",analysis["facebook/bart-large-cnn"]["Score"]["rougeL"])
240
+ st.write(f"Rouge LSum Score: ",analysis["facebook/bart-large-cnn"]["Score"]["rougeLsum"])
241
+ st.write("Result: ", analysis["facebook/bart-large-cnn"]["Result"])
242
+
243
+ st.markdown(f'<p style="color: #012d51;font-size:18px;border-radius:%;">{"Summarization Results for Model 2"}</p>', unsafe_allow_html=True)
244
+ # st.write("Summarization Results for Model 2")
245
+ st.write("Model name: tuner007/pegasus_summarizer")
246
+ st.write("Rouge Scores: ")
247
+ st.write("Rouge 1 Score: ",analysis["tuner007/pegasus_summarizer"]["Score"]["rouge1"])
248
+ st.write("Rouge 2 Score: ",analysis["tuner007/pegasus_summarizer"]["Score"]["rouge2"])
249
+ st.write("Rouge L Score: ",analysis["tuner007/pegasus_summarizer"]["Score"]["rougeL"])
250
+ st.write("Rouge LSum Score: ",analysis["tuner007/pegasus_summarizer"]["Score"]["rougeLsum"])
251
+ st.write("Result: ", analysis["tuner007/pegasus_summarizer"]["Result"][0])
252
+
253
+
254
+
255
+ st.markdown(f'<p style="color: #012d51;font-size:18px;border-radius:%;">{"Summarization Results for Model 3"}</p>', unsafe_allow_html=True)
256
+ # st.write("Summarization Results for Model 3")
257
+ st.write("Model name: sshleifer/distilbart-cnn-12-6")
258
+ st.write("Rouge Scores: ")
259
+ st.write("Rouge 1 Score: ",analysis["sshleifer/distilbart-cnn-12-6"]["Score"]["rouge1"])
260
+ st.write("Rouge 2 Score: ",analysis["sshleifer/distilbart-cnn-12-6"]["Score"]["rouge2"])
261
+ st.write("Rouge L Score: ",analysis["sshleifer/distilbart-cnn-12-6"]["Score"]["rougeL"])
262
+ st.write("Rouge LSum Score: ",analysis["sshleifer/distilbart-cnn-12-6"]["Score"]["rougeLsum"])
263
+
264
+ st.write("Result: ", analysis["sshleifer/distilbart-cnn-12-6"]["Result"])
265
+
266
+
267
+
268
+
269
+ #OBJECT DETECTION
270
+
271
+ def yolo_tiny(name):
272
+ image = read_image(name)
273
+
274
+ model = YolosForObjectDetection.from_pretrained('hustvl/yolos-tiny')
275
+ image_processor = YolosImageProcessor.from_pretrained("hustvl/yolos-tiny")
276
+
277
+ inputs = image_processor(images=image, return_tensors="pt")
278
+ outputs = model(**inputs)
279
+
280
+ # model predicts bounding boxes and corresponding COCO classes
281
+ logits = outputs.logits
282
+ bboxes = outputs.pred_boxes
283
+
284
+
285
+ # print results
286
+ target_sizes = torch.tensor([image.shape[::-1][:2]])
287
+
288
+ results = image_processor.post_process_object_detection(outputs, threshold=0.7, target_sizes=target_sizes)[0]
289
+
290
+ label_ = []
291
+ bboxes = []
292
+
293
+ for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
294
+ box = [round(i, 2) for i in box.tolist()]
295
+ print(
296
+ f"Detected {model.config.id2label[label.item()]} with confidence "
297
+ f"{round(score.item(), 3)} at location {box}"
298
+ )
299
+
300
+ label_.append(model.config.id2label[label.item()])
301
+ bboxes.append(np.asarray(box,dtype="int"))
302
+ bboxes = torch.tensor(bboxes, dtype=torch.int)
303
+
304
+ img=draw_bounding_boxes(image, bboxes,labels = label_, width=3)
305
+ img = torchvision.transforms.ToPILImage()(img)
306
+ return img
307
+ # img.show()
308
+
309
+
310
+
311
+ def resnet_101(name):
312
+ image = read_image(name)
313
+ processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-101")
314
+ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-101")
315
+
316
+ inputs = processor(images=image, return_tensors="pt")
317
+ outputs = model(**inputs)
318
+
319
+ # convert outputs (bounding boxes and class logits) to COCO API
320
+ # let's only keep detections with score > 0.9
321
+ target_sizes = torch.tensor([image.shape[::-1][:2]])
322
+ results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.7)[0]
323
+ label_ = []
324
+ bboxes = []
325
+ for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
326
+ box = [round(i, 2) for i in box.tolist()]
327
+ print(
328
+ f"Detected {model.config.id2label[label.item()]} with confidence "
329
+ f"{round(score.item(), 3)} at location {box}")
330
+ label_.append(model.config.id2label[label.item()])
331
+ bboxes.append(np.asarray(box,dtype="int"))
332
+ bboxes = torch.tensor(bboxes, dtype=torch.int)
333
+
334
+
335
+ bboxes = torch.tensor(bboxes, dtype=torch.int)
336
+
337
+ img=draw_bounding_boxes(image, bboxes,labels = label_, width=3)
338
+ img = torchvision.transforms.ToPILImage()(img)
339
+ return img
340
+
341
+
342
+
343
+
344
+
345
+ def resnet_50(name):
346
+ image = read_image(name)
347
+ processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
348
+ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
349
+
350
+ inputs = processor(images=image, return_tensors="pt")
351
+ outputs = model(**inputs)
352
+
353
+ # convert outputs (bounding boxes and class logits) to COCO API
354
+ # let's only keep detections with score > 0.9
355
+ target_sizes = torch.tensor([image.shape[::-1][:2]])
356
+ results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.7)[0]
357
+ label_ = []
358
+ bboxes = []
359
+ for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
360
+ box = [round(i, 2) for i in box.tolist()]
361
+ print(
362
+ f"Detected {model.config.id2label[label.item()]} with confidence "
363
+ f"{round(score.item(), 3)} at location {box}"
364
+ )
365
+ label_.append(model.config.id2label[label.item()])
366
+ bboxes.append(np.asarray(box,dtype="int"))
367
+ bboxes = torch.tensor(bboxes, dtype=torch.int)
368
+
369
+ bboxes = torch.tensor(bboxes, dtype=torch.int)
370
+
371
+ img=draw_bounding_boxes(image, bboxes,labels = label_, width=3)
372
+ img = torchvision.transforms.ToPILImage()(img)
373
+ return img
374
+
375
+
376
+
377
+ def object_detection():
378
+ # st.write("Upload your image: ")
379
+ # uploaded_files = ""
380
+ # uploaded_files = st.file_uploader("Choose a image file", accept_multiple_files=True)
381
+
382
+ option = st.selectbox(
383
+ 'What image you want for analysis?',
384
+ ("Choose an image for object detection analysis from the options below:",'Cat and Dog', '2 lazy cats chilling on a couch', 'An astronaut riding wild horse'))
385
+
386
+ if option == 'Cat and Dog' or option == '2 lazy cats chilling on a couch' or option == 'An astronaut riding wild horse':
387
+ st.write('You selected:', option)
388
+
389
+ if option == 'Cat and Dog':
390
+ name = "cat_dog.jpg"
391
+ st.image("cat_dog.jpg")
392
+
393
+ if option == '2 lazy cats chilling on a couch':
394
+ name = "cat_remote.jpg"
395
+ st.image("cat_remote.jpg")
396
+
397
+ if option == 'An astronaut riding wild horse':
398
+ name = "astronaut_rides_horse.png"
399
+ st.image("astronaut_rides_horse.png")
400
+
401
+ if st.button("Select"):
402
+ # global file_data
403
+ # st.write("filename:", uploaded_files)
404
+ # for uploaded_file in uploaded_files:
405
+ # print("here")
406
+ # file_data = open(uploaded_file.name).read()
407
+ st.write("filename:", name)
408
+ # name = uploaded_file.name
409
+ st.image([yolo_tiny(name),resnet_101(name),resnet_50(name)],caption=["hustvl/yolos-tiny","facebook/detr-resnet-101","facebook/detr-resnet-50"])
410
+
411
+
412
+ def task_categorization_model_predictions():
413
+ st.image("./panelup.png")
414
+
415
+ # st.title("Text Analysis App")
416
+
417
+ data = ""
418
+
419
+ classifier = pipeline("zero-shot-classification",model="facebook/bart-large-mnli")
420
+
421
+ global check
422
+
423
+ st.markdown(f'<p style="color: #012d51;font-size:18px;border-radius:%;">{"Write down below the description of your AI application in few sentences:"}</p>', unsafe_allow_html=True)
424
+
425
+ prompt = st.text_input(" ")
426
+
427
+ st.write("")
428
+ st.write("")
429
+
430
+ if prompt != "":
431
+ # sbert_saved_model = torch.load("Sbert_saved_model", map_location=torch.device('cpu')).to("cpu")
432
+ # model = sbert_saved_model.to("cpu")
433
+ # tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-mpnet-base-v2")
434
+ # pipe = TextClassificationPipeline(model= model, tokenizer=tokenizer, return_all_scores=True)
435
+ # # outputs a list of dicts like [[{'label': 'NEGATIVE', 'score': 0.0001223755971295759}, {'label': 'POSITIVE', 'score': 0.9998776316642761}]]
436
+
437
+ # # prompt = ["What is the the best ai for putting text report into data table?","How can I generate car sales agreement with ai model?","AI model to detect burglar on 48 hours of cctv video footage","I need Ai model help me with rewriting 50 financial statements emails into one summary report ?","I need a model for extracting person from an image"]
438
+ # # responses = pipe(prompt)
439
+
440
+
441
+ # models_list = pd.read_csv("models.csv")
442
+ # # st.write(get_top_3(prompt))
443
+
444
+ # top_cat, top_models = get_top_3(prompt)
445
+ # # prompt = input("Enter your AI task idea:")
446
+ # # top_cats,cat_to_models = get_models(prompt)
447
+
448
+ # # top_models = cat_to_models[top_cats[0]]
449
+
450
+ # top_cat = " " + top_cat[0].upper() + top_cat[1:]
451
+
452
+
453
+
454
+ st.markdown(f'<p style="color: #012d51;font-size:24px;border-radius:%;">{"Recognized AI Domain: "}</p>', unsafe_allow_html=True)
455
+
456
+ domains = ["Computer Vision Task","Natural Language Processing Problem","Audio Operations Problem","Tabular Data Task","Reinforcement Learning Problem","Time Series Forecasting Problem"]
457
+
458
+
459
+
460
+ #st.write(classifier(prompt, domains))
461
+ domain = classifier(prompt, domains)["labels"][0]
462
+
463
+ st.markdown(f'<p style="background-color:#12d51; color:#1782ea;font-size:18px;border-radius:%;">{domain}</p>', unsafe_allow_html=True)
464
+ # st.write("Recommended AI Domain Type: ",top_cat)
465
+ check = 0
466
+ if st.button("This seems accurate"):
467
+ check = 1
468
+ if st.button("Show me other likely category recommendations:"):
469
+ if domain == "Tabular Data Problem":
470
+ if st.button("Computer Vision Task"):
471
+ domain = "Computer Vision Task"
472
+ check = 1
473
+ if st.button("Natural Language Processing Problem"):
474
+ domain = "Natural Language Processing Problem"
475
+ check = 1
476
+ if st.button("Multimodal AI Model"):
477
+ domain = "Multimodal AI Model"
478
+ check = 1
479
+ if st.button("Audio Operations Problem"):
480
+ domain = "Audio Operations Problem"
481
+ check = 1
482
+ # if st.button("Tabular Data Task"):
483
+ # domain = "Tabular Data Task"
484
+ if st.button("Reinforcement Learning Problem"):
485
+ domain = "Reinforcement Learning Problem"
486
+ check = 1
487
+ if st.button("Time Series Forecasting Problem"):
488
+ domain = "Time Series Forecasting Problem"
489
+ check = 1
490
+
491
+
492
+ if domain == "Computer Vision Task":
493
+ # if st.button("Computer Vision Task"):
494
+ # domain = "Computer Vision Task"
495
+ if st.button("Natural Language Processing Problem"):
496
+ domain = "Natural Language Processing Problem"
497
+ check = 1
498
+
499
+ if st.button("Multimodal AI Model"):
500
+ domain = "Multimodal AI Model"
501
+ check = 1
502
+
503
+ if st.button("Audio Operations Problem"):
504
+ domain = "Audio Operations Problem"
505
+ check = 1
506
+ if st.button("Tabular Data Task"):
507
+ domain = "Tabular Data Task"
508
+ check = 1
509
+ if st.button("Reinforcement Learning Problem"):
510
+ domain = "Reinforcement Learning Problem"
511
+ check = 1
512
+ if st.button("Time Series Forecasting Problem"):
513
+ domain = "Time Series Forecasting Problem"
514
+ check = 1
515
+
516
+
517
+ if domain == "Natural Language Processing Problem":
518
+ if st.button("Computer Vision Task"):
519
+ domain = "Computer Vision Task"
520
+ check = 1
521
+ # if st.button("Natural Language Processing Problem"):
522
+ # domain = "Natural Language Processing Problem"
523
+ if st.button("Multimodal AI Model"):
524
+ domain = "multimodal"
525
+ check = 1
526
+ if st.button("Audio Operations Problem"):
527
+ domain = "Audio Operations Problem"
528
+ check = 1
529
+ if st.button("Tabular Data Task"):
530
+ domain = "Tabular Data Task"
531
+ check = 1
532
+ if st.button("Reinforcement Learning Problem"):
533
+ domain = "Reinforcement Learning Problem"
534
+ check = 1
535
+ if st.button("Time Series Forecasting Problem"):
536
+ domain = "Time Series Forecasting Problem"
537
+ check = 1
538
+
539
+
540
+ if domain == "Multimodal AI Model":
541
+ if st.button("Computer Vision Task"):
542
+ domain = "Computer Vision Task"
543
+ check = 1
544
+ if st.button("Natural Language Processing Problem"):
545
+ domain = "Natural Language Processing Problem"
546
+ check = 1
547
+ # if st.button("Multimodal AI Model"):
548
+ # domain = "Multimodal AI Model"
549
+ if st.button("Audio Operations Problem"):
550
+ domain = "Audio Operations Problem"
551
+ check = 1
552
+ if st.button("Tabular Data Task"):
553
+ domain = "Tabular Data Task"
554
+ check = 1
555
+ if st.button("Reinforcement Learning Problem"):
556
+ domain = "Reinforcement Learning Problem"
557
+ check = 1
558
+ if st.button("Time Series Forecasting Problem"):
559
+ domain = "Time Series Forecasting Problem"
560
+ check = 1
561
+
562
+
563
+ if domain == "audio":
564
+ if st.button("Computer Vision Task"):
565
+ domain = "Computer Vision Task"
566
+ check = 1
567
+ if st.button("Natural Language Processing Problem"):
568
+ domain = "Natural Language Processing Problem"
569
+ check = 1
570
+ if st.button("Multimodal AI Model"):
571
+ domain = "Multimodal AI Model"
572
+ check = 1
573
+ # if st.button("Audio Operations Problem"):
574
+ # domain = "Audio Operations Problem"
575
+ if st.button("Tabular Data Task"):
576
+ domain = "Tabular Data Task"
577
+ check = 1
578
+ if st.button("Reinforcement Learning Problem"):
579
+ domain = "Reinforcement Learning Problem"
580
+ check = 1
581
+ if st.button("Time Series Forecasting Problem"):
582
+ domain = "Time Series Forecasting Problem"
583
+ check = 1
584
+
585
+
586
+ if domain == "reinforcement-learning":
587
+ if st.button("Computer Vision Task"):
588
+ domain = "Computer Vision Task"
589
+ check = 1
590
+ if st.button("Natural Language Processing Problem"):
591
+ domain = "Natural Language Processing Problem"
592
+ check = 1
593
+ if st.button("Multimodal AI Model"):
594
+ domain = "multimodal"
595
+ check = 1
596
+ if st.button("Audio Operations Problem"):
597
+ domain = "Audio Operations Problem"
598
+ check = 1
599
+ if st.button("Tabular Data Task"):
600
+ domain = "Tabular Data Task"
601
+ check = 1
602
+ # if st.button("Reinforcement Learning Problem"):
603
+ # domain = "Reinforcement Learning Problem"
604
+ if st.button("Time Series Forecasting Problem"):
605
+ domain = "Time Series Forecasting Problem"
606
+ check = 1
607
+
608
+ if domain == "Time Series Forecasting":
609
+ if st.button("Computer Vision Task"):
610
+ domain = "Computer Vision Task"
611
+ check = 1
612
+ if st.button("Natural Language Processing Problem"):
613
+ domain = "Natural Language Processing Problem"
614
+ check = 1
615
+ if st.button("Multimodal AI Model"):
616
+ domain = "Multimodal AI Model"
617
+ check = 1
618
+ if st.button("Audio Operations Problem"):
619
+ domain = "Audio Operations Problem"
620
+ check = 1
621
+ if st.button("Tabular Data Task"):
622
+ domain = "Tabular Data Task"
623
+ check = 1
624
+ if st.button("Reinforcement Learning Problem"):
625
+ domain = "Reinforcement Learning Problem"
626
+ check = 1
627
+ # if st.button("Time Series Forecasting Problem"):
628
+ # domain = "Time Series Forecasting Problem"
629
+
630
+ # st.write("Recommended Models for category: ",top_cats[0], " are:",top_models)
631
+
632
+ # st.write("Recommended Task category: ",top_models[0])
633
+
634
+
635
+
636
+ knowledge_base_tasks = {"Computer Vision Task":['depth-estimation', 'image-classification', 'image-segmentation',
637
+ 'image-to-image', 'object-detection', 'video-classification',
638
+ 'unconditional-image-generation', 'zero-shot-image-classification'],"Natural Language Processing Problem":[
639
+ 'conversational', 'fill-mask', 'question-answering',
640
+ 'sentence-similarity', 'summarization', 'table-question-answering',
641
+ 'text-classification', 'text-generation', 'token-classification',
642
+ 'translation', 'zero-shot-classification'],"Audio Operations Problem":["audio-classification","audio-to-audio","automatic-speech-recognition",
643
+ "text-to-speech"],"Tabular Data Task":["tabular-classification","tabular-regression"],"others":["document-question-answering",
644
+ "feature-extraction","image-to-text","text-to-image","text-to-video","visual-question-answering"],
645
+ "Reinforcement Learning Problem":["reinforcement-learning"],"time-series-forecasting":["time-series-forecasting"]}
646
+
647
+ # st.write(check)
648
+ # st.write(domain)
649
+ if check == 1:
650
+
651
+ category = classifier(prompt, knowledge_base_tasks[domain])["labels"][0]
652
+
653
+
654
+ st.markdown(f'<p style="color: #012d51;font-size:24px;border-radius:%;">{"Recognized sub category in Domain: "+domain}</p>', unsafe_allow_html=True)
655
+
656
+ st.markdown(f'<p style="background-color:#12d51; color:#1782ea;font-size:18px;border-radius:%;">{category}</p>', unsafe_allow_html=True)
657
+
658
+
659
+ top_models = get_top_3(category)
660
+ #st.write(top_models)
661
+ st.markdown(f'<p style=" margin-left: 0px;color: #012d51;font-size:18px;border-radius:%;">{"The best models selected for this domain:"}</p>', unsafe_allow_html=True)
662
+
663
+
664
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"1- "+top_models[0]}</p>', unsafe_allow_html=True)
665
+
666
+ st.image("./buttons1.png")
667
+
668
+ # if st.button("Show more"):
669
+
670
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"2- "+top_models[1]}</p>', unsafe_allow_html=True)
671
+ st.image("./buttons1.png")
672
+
673
+
674
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"3- "+top_models[2]}</p>', unsafe_allow_html=True)
675
+ st.image("./buttons1.png")
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+ def model_selector_sbert():
684
+
685
+ st.image("./panelup.jpg")
686
+
687
+ # st.title("Text Analysis App")
688
+
689
+ data = ""
690
+
691
+
692
+ st.markdown(f'<p style="color: #012d51;font-size:18px;border-radius:%;">{"Please, enter your AI task:"}</p>', unsafe_allow_html=True)
693
+
694
+ prompt = st.text_input(" ")
695
+
696
+ st.write("")
697
+ st.write("")
698
+
699
+ if prompt != "":
700
+ sbert_saved_model = torch.load("Sbert_saved_model", map_location=torch.device('cpu')).to("cpu")
701
+ model = sbert_saved_model.to("cpu")
702
+ tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-mpnet-base-v2")
703
+ pipe = TextClassificationPipeline(model= model, tokenizer=tokenizer, return_all_scores=True)
704
+ # outputs a list of dicts like [[{'label': 'NEGATIVE', 'score': 0.0001223755971295759}, {'label': 'POSITIVE', 'score': 0.9998776316642761}]]
705
+
706
+ # prompt = ["What is the the best ai for putting text report into data table?","How can I generate car sales agreement with ai model?","AI model to detect burglar on 48 hours of cctv video footage","I need Ai model help me with rewriting 50 financial statements emails into one summary report ?","I need a model for extracting person from an image"]
707
+ # responses = pipe(prompt)
708
+
709
+
710
+ models_list = pd.read_csv("models.csv")
711
+ # st.write(get_top_3(prompt))
712
+
713
+ top_cat, top_models = get_top_3_a(prompt,pipe)
714
+ # prompt = input("Enter your AI task idea:")
715
+ # top_cats,cat_to_models = get_models(prompt)
716
+
717
+ # top_models = cat_to_models[top_cats[0]]
718
+
719
+ top_cat = " " + top_cat[0].upper() + top_cat[1:]
720
+ st.markdown(f'<p style="color: #012d51;font-size:24px;border-radius:%;">{"Recognized AI Domain Category: "}</p>', unsafe_allow_html=True)
721
+
722
+ st.markdown(f'<p style="background-color:#12d51; color:#1782ea;font-size:18px;border-radius:%;">{top_cat}</p>', unsafe_allow_html=True)
723
+ # st.write("Recommended AI Domain Type: ",top_cat)
724
+ # st.write("Recommended Models for category: ",top_cats[0], " are:",top_models)
725
+
726
+ # st.write("Recommended Task category: ",top_models[0])
727
+
728
+
729
+ st.markdown(f'<p style=" margin-left: 0px;color: #012d51;font-size:18px;border-radius:%;">{"The best models selected for this task:"}</p>', unsafe_allow_html=True)
730
+
731
+
732
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"1- "+top_models[0]}</p>', unsafe_allow_html=True)
733
+
734
+ st.image("./buttons1.png")
735
+
736
+ if st.button("Show more"):
737
+
738
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"2- "+top_models[1]}</p>', unsafe_allow_html=True)
739
+ st.image("./buttons1.png")
740
+
741
+
742
+ st.markdown(f'<p style="margin-left: 0px;background-color:#e1e1e1; color:#012d51;font-size:18px;border-radius:%;">{"3- "+top_models[2]}</p>', unsafe_allow_html=True)
743
+ st.image("./buttons1.png")
744
+
745
+
746
+
747
+
748
+ page_names_to_funcs = {
749
+ "Select the best Model for your AI app":model_selector_sbert,
750
+ "Compare Model Outputs on Object Detection": object_detection,
751
+ "Compare Model Outputs on Text Summarization": text_summarization
752
+ }
753
+
754
+ demo_name = st.sidebar.selectbox("Find the best model for your next AI task or compare model outputs", page_names_to_funcs.keys())
755
+ page_names_to_funcs[demo_name]()
756
+
757
+
758
+
759
+ # st.write("Recommended Most Popular Model for category ",top_cat, " is:",top_models[0])
760
+ # if st.button("Show more"):
761
+ # for i in range(1,len(top_models)):
762
+ # st.write("Model#",str(i+1),top_models[i])
763
+
764
+
765
+ # data = prompt
766
+
767
+ # # print("before len data")
768
+
769
+ # if len(data) != 0:
770
+ # # print("after len data")
771
+ # st.write("Recommended Task category: ",top_cats[0])
772
+ # st.write("Recommended Most Popular Model for category ",top_cats[0], " is:",top_models[0])
773
+ # if st.button("Show more"):
774
+ # for i in range(1,len(top_models)):
775
+ # st.write("Model#",str(i+1),top_models[i])
776
+
777
+ # st.write("Upload your file: ")
778
+ # uploaded_files = ""
779
+ # uploaded_files = st.file_uploader("Choose a text file", accept_multiple_files=True)
780
+ # if st.button("Select"):
781
+ # global file_data
782
+ # st.write("filename:", uploaded_files)
783
+ # for uploaded_file in uploaded_files:
784
+ # # print("here")
785
+ # file_data = open(uploaded_file.name,encoding="utf8").read()
786
+ # st.write("filename:", uploaded_file.name)
787
+ # # st.write(file_data[:500])
788
+ # # print("before summarizer")
789
+ # print(file_data[:500])
790
+ # analysis = summarizer(models = top_models, data = file_data[:500])
791
+ # # print("between summarizer analysis")
792
+
793
+ # z,x,c,v,b = best_model(analysis,file_data[:500])
794
+ # st.write("Best model for Task: ",z)
795
+ # st.write("\nBest model name: ",x)
796
+ # st.write("\nBest model Score: ",c)
797
+ # st.write("\nOriginal Data first 500 characters: ", v)
798
+ # st.write("\nBest Model Result: ",b)
799
+ # st.success(result)