from huggingface_hub import from_pretrained_fastai import gradio as gr from fastai.vision.all import * # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME" repo_id = "iamacaru/climate" learner = from_pretrained_fastai(repo_id) labels = learner.dls.vocab # Definimos una funciĆ³n que se encarga de llevar a cabo las predicciones def predict(text): pred,pred_idx,probs = learner.predict(text) if pred == '1': return "Climate related" else: return "Not climate related" # Textos de ejemplo examples = [ "The increasing levels of CO2 in the atmosphere are a major cause of global warming.", "I had a great time at the concert last night, the band was amazing!", "Scientists are working on new methods to reduce greenhouse gas emissions.", "The new restaurant in town serves the best sushi I've ever had.", "Climate change is causing more frequent and severe weather events around the world.", "She enjoys reading mystery novels and solving puzzles in her free time.", "Renewable energy sources like wind and solar power are essential to combating climate change.", "The software update includes several new features and bug fixes.", "Rising sea levels are threatening coastal communities and ecosystems.", "He decided to take a photography class to improve his skills." ] # Creamos la interfaz y la lanzamos. gr.Interface(fn=predict, inputs=gr.inputs.Textbox(lines=1, placeholder="Enter text here...", label="Text to predict"), outputs=gr.Textbox(label="Prediction"), examples=examples).launch(share=False)