Spaces:
Running
Running
File size: 5,073 Bytes
5ae02e5 23dd469 5ae02e5 23dd469 388fe1b 23dd469 388fe1b 23dd469 388fe1b 23dd469 5ae02e5 388fe1b 5ae02e5 388fe1b 5ae02e5 388fe1b 23dd469 388fe1b 23dd469 388fe1b 23dd469 388fe1b 5ae02e5 388fe1b 5ae02e5 23dd469 388fe1b 23dd469 388fe1b |
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
import gradio as gr
import torch
import torchaudio
import numpy as np
from transformers import AutoProcessor, SeamlessM4Tv2Model
from datetime import datetime
import time
class JarvisTranslator:
def __init__(self, model_name: str = "facebook/seamless-m4t-v2-large"):
self.processor = AutoProcessor.from_pretrained(model_name)
self.model = SeamlessM4Tv2Model.from_pretrained(model_name)
self.sample_rate = self.model.config.sampling_rate
self.language_codes = {
"English": "eng",
"Spanish": "spa",
"French": "fra",
"German": "deu",
"Italian": "ita",
"Portuguese": "por",
"Russian": "rus",
"Chinese": "cmn",
"Japanese": "jpn"
}
def translate(self, text: str, src_lang: str, tgt_lang: str) -> tuple[int, np.ndarray]:
inputs = self.processor(text=text, src_lang=src_lang, return_tensors="pt")
audio_array = self.model.generate(**inputs, tgt_lang=tgt_lang)[0].cpu().numpy().squeeze()
return self.sample_rate, audio_array
def create_jarvis_interface():
# Custom CSS for Jarvis-like theme
css = """
#jarvis-container {
background-color: #000000;
color: #00ffff;
font-family: 'Courier New', monospace;
padding: 20px;
border-radius: 10px;
border: 2px solid #00ffff;
}
#status-circle {
width: 150px;
height: 150px;
border: 4px solid #00ffff;
border-radius: 50%;
margin: 20px auto;
position: relative;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0.4); }
70% { box-shadow: 0 0 0 20px rgba(0, 255, 255, 0); }
100% { box-shadow: 0 0 0 0 rgba(0, 255, 255, 0); }
}
.custom-button {
background-color: transparent !important;
border: 2px solid #00ffff !important;
color: #00ffff !important;
font-family: 'Courier New', monospace !important;
}
.custom-button:hover {
background-color: rgba(0, 255, 255, 0.1) !important;
}
.status-text {
color: #00ffff;
text-align: center;
font-size: 1.2em;
margin: 10px 0;
}
.time-display {
position: absolute;
top: 10px;
right: 10px;
color: #00ffff;
font-family: 'Courier New', monospace;
}
"""
translator = JarvisTranslator()
def update_status():
return f"JARVIS AI SYSTEM ACTIVE\nTime: {datetime.now().strftime('%H:%M:%S')}"
def process_command(text, src_lang, tgt_lang):
status = f"Processing command: {text}\nSource: {src_lang} → Target: {tgt_lang}"
time.sleep(1) # Simulate processing
try:
sample_rate, audio = translator.translate(text,
translator.language_codes[src_lang],
translator.language_codes[tgt_lang])
return audio, status + "\nStatus: Translation complete"
except Exception as e:
return None, f"Error: {str(e)}"
with gr.Blocks(css=css, title="JARVIS AI") as demo:
with gr.Column(elem_id="jarvis-container"):
gr.Markdown("# JARVIS AI TRANSLATION SYSTEM")
# Status display
status_html = gr.HTML(value="<div id='status-circle'></div>", show_label=False)
status_text = gr.Textbox(label="System Status", value=update_status)
with gr.Row():
text_input = gr.Textbox(
label="Command Input",
placeholder="Enter text to translate...",
lines=3
)
with gr.Row():
src_lang = gr.Dropdown(
choices=list(translator.language_codes.keys()),
value="English",
label="Source Language"
)
tgt_lang = gr.Dropdown(
choices=list(translator.language_codes.keys()),
value="Spanish",
label="Target Language"
)
with gr.Row():
process_btn = gr.Button("Execute Translation", elem_classes=["custom-button"])
audio_output = gr.Audio(
label="Translated Output",
type="numpy"
)
# Event handlers
process_btn.click(
fn=process_command,
inputs=[text_input, src_lang, tgt_lang],
outputs=[audio_output, status_text]
)
demo.load(
fn=update_status,
outputs=status_text,
every=1 # Update every second
)
return demo
if __name__ == "__main__":
demo = create_jarvis_interface()
demo.launch() |