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