Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from groq import Groq | |
| import edge_tts | |
| import asyncio | |
| import random | |
| import os | |
| # --- INITIALIZATION --- | |
| # Hugging Face will look for the secret 'API_KEY_IS_HERE' in the Settings tab | |
| api_key = os.environ.get("API_KEY_IS_HERE") | |
| client = Groq(api_key=api_key) | |
| LLM_MODEL = "llama-3.3-70b-versatile" | |
| STT_MODEL = "whisper-large-v3" | |
| # --- DATASET --- | |
| LOGIC_VAULT = [ | |
| "Synthesize an optimization strategy for a sharded database architecture.", | |
| "Evaluate the logical implications of CAP theorem in a globally distributed system.", | |
| "Design a zero-trust security protocol for high-latency neural networks.", | |
| "Analyze the structural integrity of a non-blocking I/O multiplexing system." | |
| ] | |
| # --- CORE LOGIC --- | |
| def mentor_brain(user_text): | |
| challenge = random.choice(LOGIC_VAULT) | |
| sys_prompt = f"""You are a Lead Systems Architect. | |
| 1. Acknowledge user input with high-level precision. | |
| 2. Present this architectural challenge: {challenge} | |
| 3. Use bold, technical language. | |
| 4. Maximum 35 words.""" | |
| completion = client.chat.completions.create( | |
| model=LLM_MODEL, | |
| messages=[{"role": "system", "content": sys_prompt}, {"role": "user", "content": user_text}] | |
| ) | |
| return completion.choices[0].message.content | |
| def transcribe_voice(audio_path): | |
| with open(audio_path, "rb") as file: | |
| return client.audio.transcriptions.create(file=(audio_path, file.read()), model=STT_MODEL, response_format="text") | |
| async def synthesize_voice(text): | |
| output_file = "mentor_hq.mp3" | |
| communicate = edge_tts.Communicate(text, "en-US-AndrewNeural") | |
| await communicate.save(output_file) | |
| return output_file | |
| async def master_process(audio_path): | |
| if not audio_path: return "AWAITING SIGNAL...", "...", None | |
| try: | |
| user_speech = transcribe_voice(audio_path) | |
| mentor_text = mentor_brain(user_speech) | |
| mentor_audio = await synthesize_voice(mentor_text) | |
| return user_speech, mentor_text, mentor_audio | |
| except Exception as e: | |
| return f"Error: {str(e)}", "Please check API Key secrets.", None | |
| # --- UI STYLING --- | |
| titan_css = """ | |
| .gradio-container {background-color: #000000 !important; font-family: 'Helvetica', 'Arial', sans-serif !important;} | |
| #main-header {text-align: center; color: #ffffff !important; font-weight: 900 !important; font-size: 4em !important; letter-spacing: -3px; margin-bottom: 0px; text-transform: uppercase;} | |
| #dev-tag {text-align: center; color: #00e5ff !important; font-weight: 800 !important; font-size: 1.2em !important; margin-top: -15px; letter-spacing: 5px; text-transform: uppercase;} | |
| .glow-divider {height: 3px; background: linear-gradient(90deg, transparent, #00e5ff, #0051ff, transparent); margin: 30px 0; box-shadow: 0 0 20px rgba(0, 229, 255, 0.4);} | |
| .titan-btn { | |
| background: #00e5ff !important; | |
| border: none !important; | |
| color: #000000 !important; | |
| border-radius: 0px !important; | |
| font-weight: 900 !important; | |
| text-transform: uppercase !important; | |
| letter-spacing: 2px !important; | |
| height: 50px !important; | |
| transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; | |
| } | |
| .titan-btn:hover { | |
| background: #ffffff !important; | |
| box-shadow: 0 0 30px rgba(0, 229, 255, 0.6); | |
| transform: translateY(-3px); | |
| } | |
| .obsidian-panel { | |
| border: 1px solid #111111 !important; | |
| background: #050505 !important; | |
| padding: 35px !important; | |
| border-radius: 0px !important; | |
| } | |
| input, textarea { | |
| background-color: #080808 !important; | |
| border: 1px solid #1a1a1a !important; | |
| color: #ffffff !important; | |
| font-weight: 700 !important; | |
| } | |
| """ | |
| with gr.Blocks(css=titan_css, theme=gr.themes.Base()) as demo: | |
| gr.Markdown("# LOGICFORGE", elem_id="main-header") | |
| gr.Markdown("MUHAMMAD BILAL / SENIOR DEVELOPER", elem_id="dev-tag") | |
| gr.HTML("<div class='glow-divider'></div>") | |
| with gr.Row(): | |
| with gr.Column(scale=4, elem_classes="obsidian-panel"): | |
| gr.Markdown("### 📡 NEURAL INPUT") | |
| audio_input = gr.Audio(sources="microphone", type="filepath", label="Voice Stream") | |
| submit_btn = gr.Button("INITIATE PROTOCOL", elem_classes="titan-btn") | |
| with gr.Column(scale=6, elem_classes="obsidian-panel"): | |
| gr.Markdown("### 🧠 LOGIC SYNTHESIS") | |
| user_transcript = gr.Textbox(label="Raw Transcription") | |
| ai_text_reply = gr.Textbox(label="Strategic Output") | |
| audio_output = gr.Audio(label="Auditory Feedback", autoplay=True) | |
| submit_btn.click(master_process, inputs=audio_input, outputs=[user_transcript, ai_text_reply, audio_output]) | |
| demo.launch() |