File size: 3,040 Bytes
2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 fd140bf 2d3eb46 0899e8f 2d3eb46 0899e8f fa411d1 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f 2d3eb46 0899e8f |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
import streamlit as st
import os
import librosa
import numpy as np
from transformers import pipeline
from ftplib import FTP
# Streamlit UI
st.title("Sentiment Analysis from FTP Audio Files π΅")
# User inputs for FTP connection
st.sidebar.header("π‘ FTP Login")
host = st.sidebar.text_input("Host", "cph.v4one.co.uk")
username = st.sidebar.text_input("Username", "your_username")
password = st.sidebar.text_input("Password", type="password")
remote_path = "/path/to/audio/folders" # Change based on server
# Connect and List Available Folders
if st.sidebar.button("π Connect & List Folders"):
try:
# Connect to FTP server
ftp = FTP(host, timeout=120)
ftp.login(user=username, passwd=password)
# List available folders (filter date-based ones)
folders = []
ftp.retrlines("LIST", lambda x: folders.append(x.split()[-1])) # Get directory names
available_dates = [folder for folder in folders if folder.startswith("2025")]
ftp.quit()
st.session_state["available_dates"] = available_dates
st.success("β
Connected! Select a date below.")
except Exception as e:
st.error(f"Connection failed: {e}")
# Dropdown for Date Selection
if "available_dates" in st.session_state:
selected_date = st.selectbox("π
Select a Date", st.session_state["available_dates"])
if st.button("π₯ Download & Analyze"):
try:
ftp = FTP(host)
ftp.login(user=username, passwd=password)
remote_folder = f"{remote_path}/{selected_date}"
ftp.cwd(remote_folder)
local_folder = f"temp_audio/{selected_date}"
os.makedirs(local_folder, exist_ok=True)
audio_files = []
ftp.retrlines("LIST", lambda x: audio_files.append(x.split()[-1])) # Get file names
# Download files
for file in audio_files:
local_file_path = os.path.join(local_folder, file)
with open(local_file_path, "wb") as f:
ftp.retrbinary(f"RETR {file}", f.write)
ftp.quit()
st.success(f"β
Downloaded {len(audio_files)} files from {selected_date}")
# Sentiment Analysis
sentiment_model = pipeline("sentiment-analysis")
results = []
for file in os.listdir(local_folder):
file_path = os.path.join(local_folder, file)
y, sr = librosa.load(file_path, sr=16000)
mfccs = np.mean(librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13), axis=1)
# Mock transcription (Replace with real ASR model)
text = "This is a sample transcription"
sentiment = sentiment_model(text)
results.append({"File": file, "Sentiment": sentiment[0]["label"], "Confidence": sentiment[0]["score"]})
st.write("### Sentiment Analysis Results")
st.table(results)
except Exception as e:
st.error(f"Download failed: {e}")
|