from transformers import pipeline from PIL import Image import gradio as gr # Sentiment / text classification text_classifier = pipeline( "text-classification", model="distilbert-base-uncased-finetuned-sst-2-english" ) # Fake news detection fake_detector = pipeline( "text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection" # public ) image_classifier = pipeline( "image-classification", model="microsoft/resnet-50" # public ) leaf_classifier = pipeline( "image-classification", model="linkanjarad/mobilenet_v2_1.0_224-plant-disease-identification" # public ) fruitveg_classifier = pipeline( "image-classification", model="Schram03/fruits-classification" # public ) def classify_text(text): result = text_classifier(text)[0] return {result['label']: float(result['score'])} def detect_fake(text): result = fake_detector(text)[0] return {result['label']: float(result['score'])} def classify_image(image): result = image_classifier(image)[0] return {result['label']: float(result['score'])} def detect_leaf_disease(image): result = leaf_classifier(image)[0] return {result['label']: float(result['score'])} def detect_fruitveg(image): result = fruitveg_classifier(image)[0] return {result['label']: float(result['score'])} with gr.Blocks() as demo: with gr.Tab("Text Classification"): gr.Interface(fn=classify_text, inputs="text", outputs="label") with gr.Tab("Fake News Detection"): gr.Interface(fn=detect_fake, inputs="text", outputs="label") with gr.Tab("General Image Classification"): gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="label") with gr.Tab("Leaf Disease Detection"): gr.Interface(fn=detect_leaf_disease, inputs=gr.Image(type="pil"), outputs="label") with gr.Tab("Fruit/Veg Detection"): gr.Interface(fn=detect_fruitveg, inputs=gr.Image(type="pil"), outputs="label") # def my_function(text): # return "You entered: " + text # demo = gr.Interface(fn=my_function, inputs="text", outputs="text") # demo = gr.Interface(fn=classify_image, inputs=gr.Image(type="pil"), outputs="label") demo.launch() def classify_and_detect(text): t_result = classify_text(text) f_result = detect_fake(text) return t_result, f_result gr.Interface(fn=classify_and_detect, inputs="text", outputs=["label", "label"])