Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,12 +1,25 @@ | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
             
            import torch
         | 
| 3 | 
            -
            from transformers import AutoFeatureExtractor, AutoModelForImageClassification
         | 
| 4 |  | 
| 5 | 
             
            models=[
         | 
| 6 | 
             
                "Nahrawy/AIorNot",
         | 
| 7 | 
             
                "RishiDarkDevil/ai-image-det-resnet152",
         | 
| 8 | 
             
                "arnolfokam/ai-generated-image-detector",
         | 
| 9 | 
             
            ]
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 10 |  | 
| 11 |  | 
| 12 |  | 
|  | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
             
            import torch
         | 
| 3 | 
            +
            from transformers import AutoFeatureExtractor, AutoModelForImageClassification, pipeline
         | 
| 4 |  | 
| 5 | 
             
            models=[
         | 
| 6 | 
             
                "Nahrawy/AIorNot",
         | 
| 7 | 
             
                "RishiDarkDevil/ai-image-det-resnet152",
         | 
| 8 | 
             
                "arnolfokam/ai-generated-image-detector",
         | 
| 9 | 
             
            ]
         | 
| 10 | 
            +
            pipe = pipeline("image-classification", "umm-maybe/AI-image-detector")
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            def image_classifier(image):
         | 
| 13 | 
            +
                outputs = pipe(image)
         | 
| 14 | 
            +
                results = {}
         | 
| 15 | 
            +
                for result in outputs:
         | 
| 16 | 
            +
                    results[result['label']] = result['score']
         | 
| 17 | 
            +
                return results
         | 
| 18 | 
            +
             | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
            #demo = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label", title=title, description=description)
         | 
| 22 | 
            +
            #demo.launch(show_api=False)
         | 
| 23 |  | 
| 24 |  | 
| 25 |  | 
