File size: 2,428 Bytes
20ae03e
4131ef2
eee437c
 
4131ef2
9287a0f
091757e
 
 
4131ef2
 
 
 
 
 
 
 
 
 
 
bc984a4
c59626d
4131ef2
 
7402b1a
4131ef2
 
 
 
3d52ad9
4131ef2
 
 
20ae03e
 
 
4131ef2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5e8d8bf
 
 
 
 
 
 
 
 
 
 
 
 
eee437c
5e8d8bf
 
 
 
 
 
 
 
 
 
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
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"])