Spaces:
Build error
Build error
| # -*- coding: utf-8 -*- | |
| """Copy of app.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1KoR_JrJMqzUq-XagPaxVUp874bVW_qNI | |
| """ | |
| #/default_exp app | |
| # | |
| #from fastai.vision.all import * | |
| #!pip install gradio | |
| import gradio as gr | |
| #/export | |
| def is_monet(x): return x[0].issupper | |
| #/export | |
| from fastai.vision.all import * | |
| #/export | |
| learn = load_learner('model.pkl') | |
| #/export | |
| categories = ('Manet', 'Monet') | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # export | |
| image = gr.Image() # Image input without shape argument | |
| label = gr.Label() # Label output | |
| # Define some example images (make sure these paths are correct) | |
| examples = ['monet.jpg', 'manet2.jpg', 'manet1.jpeg'] | |
| # Create the Gradio interface | |
| #intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| # Create the Gradio interface with a title and description | |
| intf = gr.Interface( | |
| fn=classify_image, | |
| inputs=image, | |
| outputs=label, | |
| examples=examples, | |
| title="Monet vs Manet Image Classifier", # Add title here | |
| description="Upload an image to classify it as either a Monet or Manet painting." # Optional description | |
| ) | |
| # Launch the interface with Inline=False to open in a separate window | |
| intf.launch(share=True) | |
| #!pip install nbdev | |
| import os | |
| os.listdir('/content') | |
| import os | |
| notebook_path = '/content/app.ipynb' | |
| print(os.path.abspath(notebook_path)) | |
| import os | |
| file_exists = os.path.isfile('/content/app.ipynb') | |
| print(file_exists) # This should return True if the file exists | |
| import os | |
| # Extract the path of the current notebook in Colab | |
| notebook_path = '/content/app.ipynb' # Replace with the actual path if different | |
| print(f"Notebook is located at: {notebook_path}") | |
| nbdev.export.nb_export('Copy of app.ipynb', 'app') | |
| print('Export successful') | |