| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| classifier = pipeline("text-classification", model="vnarasiman/unwrap-final") |
|
|
| def classify_post(text): |
| if not text.strip(): |
| return "Please enter some text." |
| |
| results = classifier(text, top_k=None) |
| |
| |
| output = "" |
| for r in sorted(results, key=lambda x: x["score"], reverse=True): |
| bar = "โ" * int(r["score"] * 20) |
| output += f"{r['label']:<20} {bar} {r['score']*100:.1f}%\n" |
| |
| return output |
|
|
| demo = gr.Interface( |
| fn=classify_post, |
| inputs=gr.Textbox( |
| lines=6, |
| placeholder="Paste a Reddit post here...", |
| label="Reddit Post" |
| ), |
| outputs=gr.Textbox( |
| label="Classification Results", |
| lines=8 |
| ), |
| title="๐ Unwrap โ Reddit Post Classifier", |
| description="Paste any Reddit post to see how it gets classified.", |
| examples=[ |
| ["I've been feeling really overwhelmed at work lately and I don't know what to do anymore."], |
| ["Just hit 1000 karma on my main account, feels good!"], |
| ["Does anyone know a good recipe for homemade pasta?"], |
| ], |
| theme=gr.themes.Soft() |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |