master
Giò Diani 2024-11-30 12:48:00 +01:00
parent d6ae817472
commit 021b828fea
3 changed files with 369 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('episodes', function (Blueprint $table) {
$table->json('sentiments_from_sub')->nullable();
});
}
};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
import polars as pl
from database import queries
from germansentiment import SentimentModel
def get_sent(ep):
data_folder = str(Path(__file__).parents[4]) + "/data/" + ep + '/normalized_vtt.csv'
df = pl.read_csv(data_folder)
model = SentimentModel()
sentiments = model.predict_sentiment(df["sentences"].to_list(), output_probabilities = True)
time = df["end"].to_list()
senti = []
for i, x in enumerate(sentiments[0]):
match x:
case "positive":
senti.append([1, sentiments[1][i][0][1]])
case "negative":
senti.append([-1, sentiments[1][i][1][1]])
case "neutral":
senti.append([0, sentiments[1][i][2][1]])
return json.dumps({"time" : time, "sentiments" : senti })
# CLI
parser = argparse.ArgumentParser(
prog="Get Seniments per Sentence", description="Get the Sentiment (Positive, Neutral, Negative) for the Sentences"
)
parser.add_argument("--episode", "-ep")
args = parser.parse_args()
queries.save_sentiments_f_sub(args.episode, get_sent(args.episode))