Spaces:
Sleeping
Sleeping
File size: 1,225 Bytes
a7cd89b 25b184e a7cd89b |
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 |
# -*- coding: utf-8 -*-
"""app.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1ADkU3rLDhb2hQ79cia8wCKiaYrFuw_a-
Ein einfaches Sentiment-Analyse-Modell (es testet die Benutzer Eingabe auf die "Stimmung" über Gradio)
"""
# pip install transformers datasets gradio
# Extrahiert erstmal die ersten 5 Bewertungen aus dem Trainingsteil des Datasets und führt eine Analyse aus
from datasets import load_dataset
from transformers import pipeline
import gradio as gr
dataset = load_dataset("yelp_polarity")
classifier = pipeline("sentiment-analysis")
sample_reviews = dataset['train']['text'][:5]
results = classifier(sample_reviews)
for review, result in zip(sample_reviews, results):
print(f"Review: {review}\nSentiment: {result['label']} (Confidence: {result['score']:.2f})\n")
def analyze_sentiment(text):
return classifier(text)[0]
iface = gr.Interface(fn=analyze_sentiment,
inputs="text",
outputs="json",
live=True,
title="Sentiment Analysis",
description="Geben Sie einen Text ein, um die Stimmung zu analysieren.")
iface.launch()
|