YashsharmaPhD commited on
Commit
2d3eb46
Β·
verified Β·
1 Parent(s): 886bc59

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pysftp
3
+ import os
4
+ import librosa
5
+ import numpy as np
6
+ from transformers import pipeline
7
+
8
+ # Configure SFTP settings
9
+ st.title("Sentiment Analysis from Remote Audio Files 🎡")
10
+
11
+ # User inputs for SFTP connection
12
+ st.sidebar.header("πŸ“‘ SFTP Login")
13
+ host = st.sidebar.text_input("Host", "cph.v4one.co.uk")
14
+ username = st.sidebar.text_input("Username", "your_username")
15
+ password = st.sidebar.text_input("Password", type="password")
16
+ remote_path = "/path/to/audio/folders" # Adjust based on your server
17
+
18
+ # Connect and List Available Folders
19
+ if st.sidebar.button("πŸ”„ Connect & List Folders"):
20
+ try:
21
+ cnopts = pysftp.CnOpts()
22
+ cnopts.hostkeys = None # Ignore host key check (only for testing)
23
+
24
+ with pysftp.Connection(host, username=username, password=password, cnopts=cnopts) as sftp:
25
+ folders = sftp.listdir(remote_path)
26
+ available_dates = [folder for folder in folders if folder.startswith("2025")] # Filter date-based folders
27
+
28
+ st.session_state["available_dates"] = available_dates # Store in session state
29
+ st.success("βœ… Connected! Select a date below.")
30
+ except Exception as e:
31
+ st.error(f"Connection failed: {e}")
32
+
33
+ # Dropdown for Date Selection
34
+ if "available_dates" in st.session_state:
35
+ selected_date = st.selectbox("πŸ“… Select a Date", st.session_state["available_dates"])
36
+
37
+ if st.button("πŸ“₯ Download & Analyze"):
38
+ with pysftp.Connection(host, username=username, password=password, cnopts=cnopts) as sftp:
39
+ local_folder = f"temp_audio/{selected_date}"
40
+ os.makedirs(local_folder, exist_ok=True) # Create local folder
41
+
42
+ remote_folder = f"{remote_path}/{selected_date}"
43
+ audio_files = sftp.listdir(remote_folder)
44
+
45
+ # Download each file
46
+ for file in audio_files:
47
+ local_file_path = os.path.join(local_folder, file)
48
+ remote_file_path = f"{remote_folder}/{file}"
49
+ sftp.get(remote_file_path, local_file_path)
50
+
51
+ st.success(f"βœ… Downloaded {len(audio_files)} files from {selected_date}")
52
+
53
+ # Sentiment Analysis
54
+ sentiment_model = pipeline("sentiment-analysis")
55
+ results = []
56
+
57
+ for file in os.listdir(local_folder):
58
+ file_path = os.path.join(local_folder, file)
59
+ y, sr = librosa.load(file_path, sr=16000)
60
+ mfccs = np.mean(librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13), axis=1)
61
+
62
+ # Mock transcription (Replace with real ASR model)
63
+ text = "This is a sample transcription"
64
+ sentiment = sentiment_model(text)
65
+
66
+ results.append({"File": file, "Sentiment": sentiment[0]["label"], "Confidence": sentiment[0]["score"]})
67
+
68
+ st.write("### Sentiment Analysis Results")
69
+ st.table(results)