File size: 3,783 Bytes
dbff261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
import streamlit as st
from backend.pipeline import run_pipeline
from backend.errors import PipelineError, SunbirdAPIError


st.title("LocGen\nTranscribe, Summarise, Translate & Get Audio all in your local language!")

input_mode = st.radio("Input type", ["Text", "Audio file"])

text_input = ""
audio_input = b""

if input_mode == "Text":
    text_input = st.text_area("Paste or type your English text here")
else:
    uploaded = st.file_uploader("Upload a 'wav' English audio file", type="wav")
    if uploaded:
        audio_input = uploaded.read()

target_language = st.selectbox(
    label="Translate summary to:",
    options=["Acholi", "Lugbara", "Luganda", "Runyankole", "Ateso", "Swahili"],
)

if st.button("Run pipeline"):
    if not text_input and not audio_input:
        st.error("Please provide text or an audio file.")
    else:
        # empty "placeholders" to be filled as the generator yields new states
        st_transcript = st.empty()
        st_summary = st.empty()
        st_translation = st.empty()
        st_audio = st.empty()
        #st_total_timing = st.empty()

        with st.spinner("Processing..."):
            try:
                # Iterate over the generator... 'update' is the dict we yielded.
                for update in run_pipeline(
                    target_language=target_language,
                    text_input=text_input,
                    audio_input=audio_input,
                ):
                    state = update["current_state"]
                    results = update["results"]

                    # As each step finishes, fill in its text block
                    if state == "transcription":
                        if results["transcript"]:
                            with st_transcript.container():
                                st.subheader("Transcript")
                                st.write(results["transcript"])
                                # st.write(f"Transcript timing: {results['timing']['transcription']}")

                    elif state == "summarization":
                        with st_summary.container():
                            st.subheader("Summary")
                            st.write(results["summary"])
                            # st.write(f"Transcript timing: {results['timing']['summarization']}")

                    elif state == "translation":
                        with st_translation.container():
                            st.subheader("Translated Summary")
                            st.write(results["translation"])
                            # st.write(f"Translation timing: {results['timing']['translation']}")

                    elif state == "audio_clip":
                        with st_audio.container():
                            st.subheader("Audio")
                            if results["truncated"] is True:
                                st.write("Note: Summary was truncated")
                            else:
                                st.write("Summary intact! (not truncated)")
                            st.audio(data=results["audio"])
                            # st.write(f"Audio clip timing: {results['timing']['audio_clip']}")

                    #elif state == "complete":
                     #   with st_total_timing.container():
                            # st.write(f"\n\nTotal timing: {results['timing']['total']}")

            except PipelineError as e:
                st.error(f"Processing failed: {e}")
                st.exception(e)
            except SunbirdAPIError as e:
                st.error("API error while processing. Please try again later.")
                st.exception(e)
            except Exception as e:
                st.error("An unexpected error occurred.")
                st.exception(e)