artificialguybr commited on
Commit
d8f2cab
1 Parent(s): 0ff2f1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -50
app.py CHANGED
@@ -1,57 +1,53 @@
1
- import gradio as gr
2
  from gradio_client import Client
 
3
 
4
- def process_video(video_url, target_language, translate_video):
5
- try:
6
- client = Client("https://artificialguybr-video-translation-transcription.hf.space/")
7
- result = client.predict(
8
- video_url,
9
- target_language,
10
- translate_video,
11
- api_name="/predict"
12
- )
13
- return result
14
- except Exception as e:
15
- print(f"Error al llamar a la API: {e}")
16
- return "Ocurrió un error al procesar el vídeo."
17
 
18
- # Componentes de Gradio
19
- video_url = gr.Textbox(label="URL del Vídeo", placeholder="Inserte la URL del vídeo aquí")
20
- dropdown = gr.Dropdown(
21
- choices=[
22
- "Afrikáans", "Albanés", "Amárico", "Árabe", "Armenio", "Azerbaiyano", "Vasco",
23
- "Bielorruso", "Bengalí", "Bosnio", "Búlgaro", "Catalán", "Cebuano", "Chichewa",
24
- "Chino (Simplificado)", "Chino (Tradicional)", "Corso", "Croata", "Checo",
25
- "Danés", "Holandés", "Inglés", "Esperanto", "Estonio", "Filipino", "Finlandés",
26
- "Francés", "Frisón", "Gallego", "Georgiano", "Alemán", "Griego", "Gujarati",
27
- "Criollo haitiano", "Hausa", "Hawaiano", "Hebreo", "Hindi", "Hmong", "Húngaro",
28
- "Islandés", "Igbo", "Indonesio", "Irlandés", "Italiano", "Japonés", "Javanés",
29
- "Canarés", "Kazajo", "Jemer", "Coreano", "Kurdo (Kurmanji)", "Kirguís", "Lao",
30
- "Latín", "Letón", "Lituano", "Luxemburgués", "Macedonio", "Malagasy",
31
- "Malayo", "Malayalam", "Maltés", "Maorí", "Maratí", "Mongol", "Myanmar (Birmano)",
32
- "Nepalí", "Noruego", "Odia", "Pastún", "Persa", "Polaco", "Portugués", "Panyabí",
33
- "Rumano", "Ruso", "Samoano", "Gaélico escocés", "Serbio", "Sesotho", "Shona",
34
- "Sindhi", "Cingalés", "Eslovaco", "Esloveno", "Somalí", "Español", "Sundanés",
35
- "Suajili", "Sueco", "Tayiko", "Tamil", "Telugu", "Tailandés", "Turco", "Ucraniano",
36
- "Urdu", "Uigur", "Uzbeko", "Vietnamita", "Galés", "Xhosa", "Yidis", "Yoruba", "Zulú"
37
- ],
38
- label="Idioma de Destino para Traducción"
39
- )
40
- checkbox = gr.Checkbox(label="Traducir Vídeo", value=True)
 
 
 
41
 
42
- # Interfaz de Gradio
43
  iface = gr.Interface(
44
- fn=process_video,
45
- inputs=[video_url, dropdown, checkbox],
46
- outputs=gr.Video(),
47
- live=False,
48
- title="Traducción y Transcripción de Vídeo con IA",
49
- description="Inserta la URL del vídeo y selecciona el idioma de destino para la traducción. Esta herramienta utiliza la API de traducción y transcripción de vídeo.",
50
- gr.Markdown("""
51
- **Nota:**
52
- - El límite de vídeo es de 15 minutos. Realizará la transcripción y traducción de subtítulos.
53
- - La herramienta utiliza modelos de código abierto para todos los modelos. Es una versión alfa.
54
- """),
55
  )
56
 
57
- iface.launch()
 
 
 
 
 
 
 
 
 
 
1
  from gradio_client import Client
2
+ import gradio as gr
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ def interact_with_api(video_url, target_language, translate_video):
6
+ client = Client("https://artificialguybr-video-translation-transcription.hf.space/")
7
+ result = client.predict(
8
+ video_url,
9
+ target_language,
10
+ translate_video,
11
+ api_name="/predict"
12
+ )
13
+ return result
14
+
15
+ # Lista de opções de idiomas
16
+ language_options = [
17
+ "Afrikaans", "Albanian", "Amharic", "Arabic", "Armenian", "Azerbaijani", "Basque", "Belarusian",
18
+ "Bengali", "Bosnian", "Bulgarian", "Catalan", "Cebuano", "Chichewa", "Chinese (Simplified)",
19
+ "Chinese (Traditional)", "Corsican", "Croatian", "Czech", "Danish", "Dutch", "English", "Esperanto",
20
+ "Estonian", "Filipino", "Finnish", "French", "Frisian", "Galician", "Georgian", "German", "Greek",
21
+ "Gujarati", "Haitian Creole", "Hausa", "Hawaiian", "Hebrew", "Hindi", "Hmong", "Hungarian", "Icelandic",
22
+ "Igbo", "Indonesian", "Irish", "Italian", "Japanese", "Javanese", "Kannada", "Kazakh", "Khmer",
23
+ "Korean", "Kurdish (Kurmanji)", "Kyrgyz", "Lao", "Latin", "Latvian", "Lithuanian", "Luxembourgish",
24
+ "Macedonian", "Malagasy", "Malay", "Malayalam", "Maltese", "Maori", "Marathi", "Mongolian",
25
+ "Myanmar (Burmese)", "Nepali", "Norwegian", "Odia", "Pashto", "Persian", "Polish", "Portuguese",
26
+ "Punjabi", "Romanian", "Russian", "Samoan", "Scots Gaelic", "Serbian", "Sesotho", "Shona", "Sindhi",
27
+ "Sinhala", "Slovak", "Slovenian", "Somali", "Spanish", "Sundanese", "Swahili", "Swedish", "Tajik",
28
+ "Tamil", "Telugu", "Thai", "Turkish", "Ukrainian", "Urdu", "Uyghur", "Uzbek", "Vietnamese", "Welsh",
29
+ "Xhosa", "Yiddish", "Yoruba", "Zulu"
30
+ ]
31
 
 
32
  iface = gr.Interface(
33
+ fn=interact_with_api,
34
+ inputs=[
35
+ gr.Video(label="Upload Video or Enter URL"),
36
+ gr.Dropdown(choices=language_options, label="Target Language for Translation", value="English"),
37
+ gr.Checkbox(label="Translate Video", value=True, info="Check to translate the video to the selected language. Uncheck for transcription only."),
38
+ ],
39
+ outputs="video",
40
+ title="VIDEO TRANSCRIPTION AND TRANSLATION",
41
+ description="""This tool was developed by [@artificialguybr](https://twitter.com/artificialguybr) using entirely open-source tools. Special thanks to Hugging Face for the GPU support. Test the [Video Dubbing](https://huggingface.co/spaces/artificialguybr/video-dubbing) space!""",
42
+ allow_flagging=False
 
43
  )
44
 
45
+ with gr.Blocks() as demo:
46
+ iface.render()
47
+ gr.Markdown("""
48
+ **Note:**
49
+ - Video limit is 15 minutes. It will do the transcription and translate of subtitles.
50
+ - The tool uses open-source models for all models. It's an alpha version.
51
+ """)
52
+ demo.queue(concurrency_count=1, max_size=15)
53
+ demo.launch()