import streamlit as st from transformers import pipeline import pandas as pd import os import azure.cognitiveservices.speech as speechsdk import base64 import torch dialects = {"Palestinian/Jordanian": "P", "Syrian": "S", "Lebanese": "L", "Egyptian": "E"} pipeline = pipeline(task="translation", model="guymorlan/English2Dialect") st.title("English to Levantine Arabic") num_translations = st.sidebar.selectbox("Number of Translations Per Dialect:", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], index=0) input_text = st.text_input("Enter English text:") @st.cache(hash_funcs={torch.nn.parameter.Parameter: lambda parameter: parameter.data.numpy()}) def get_translation(input_text, num_translations): inputs = [f"{val} {input_text}" for val in dialects.values()] result = pipeline(inputs, max_length=1024, num_return_sequences=num_translations, num_beams=max(num_translations, 5)) return result if input_text: result = get_translation(input_text, num_translations) #df = pd.DataFrame({"Dialect": [x for x in dialects.keys()], # "Translation": [x["translation_text"] for x in result]}) for i in range(len(result)): # play = st.button("Play Audio (Machine Generated)") st.markdown(f"