bkbilal09 commited on
Commit
7d63b1c
·
verified ·
1 Parent(s): 99154a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -0
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from groq import Groq
3
+ import edge_tts
4
+ import asyncio
5
+ import random
6
+ import os
7
+
8
+ # --- INITIALIZATION ---
9
+ # Hugging Face will look for the secret 'API_KEY_IS_HERE' in the Settings tab
10
+ api_key = os.environ.get("API_KEY_IS_HERE")
11
+ client = Groq(api_key=api_key)
12
+
13
+ LLM_MODEL = "llama-3.3-70b-versatile"
14
+ STT_MODEL = "whisper-large-v3"
15
+
16
+ # --- DATASET ---
17
+ LOGIC_VAULT = [
18
+ "Synthesize an optimization strategy for a sharded database architecture.",
19
+ "Evaluate the logical implications of CAP theorem in a globally distributed system.",
20
+ "Design a zero-trust security protocol for high-latency neural networks.",
21
+ "Analyze the structural integrity of a non-blocking I/O multiplexing system."
22
+ ]
23
+
24
+ # --- CORE LOGIC ---
25
+ def mentor_brain(user_text):
26
+ challenge = random.choice(LOGIC_VAULT)
27
+ sys_prompt = f"""You are a Lead Systems Architect.
28
+ 1. Acknowledge user input with high-level precision.
29
+ 2. Present this architectural challenge: {challenge}
30
+ 3. Use bold, technical language.
31
+ 4. Maximum 35 words."""
32
+
33
+ completion = client.chat.completions.create(
34
+ model=LLM_MODEL,
35
+ messages=[{"role": "system", "content": sys_prompt}, {"role": "user", "content": user_text}]
36
+ )
37
+ return completion.choices[0].message.content
38
+
39
+ def transcribe_voice(audio_path):
40
+ with open(audio_path, "rb") as file:
41
+ return client.audio.transcriptions.create(file=(audio_path, file.read()), model=STT_MODEL, response_format="text")
42
+
43
+ async def synthesize_voice(text):
44
+ output_file = "mentor_hq.mp3"
45
+ communicate = edge_tts.Communicate(text, "en-US-AndrewNeural")
46
+ await communicate.save(output_file)
47
+ return output_file
48
+
49
+ async def master_process(audio_path):
50
+ if not audio_path: return "AWAITING SIGNAL...", "...", None
51
+ try:
52
+ user_speech = transcribe_voice(audio_path)
53
+ mentor_text = mentor_brain(user_speech)
54
+ mentor_audio = await synthesize_voice(mentor_text)
55
+ return user_speech, mentor_text, mentor_audio
56
+ except Exception as e:
57
+ return f"Error: {str(e)}", "Please check API Key secrets.", None
58
+
59
+ # --- UI STYLING ---
60
+ titan_css = """
61
+ .gradio-container {background-color: #000000 !important; font-family: 'Helvetica', 'Arial', sans-serif !important;}
62
+ #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;}
63
+ #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;}
64
+ .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);}
65
+ .titan-btn {
66
+ background: #00e5ff !important;
67
+ border: none !important;
68
+ color: #000000 !important;
69
+ border-radius: 0px !important;
70
+ font-weight: 900 !important;
71
+ text-transform: uppercase !important;
72
+ letter-spacing: 2px !important;
73
+ height: 50px !important;
74
+ transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
75
+ }
76
+ .titan-btn:hover {
77
+ background: #ffffff !important;
78
+ box-shadow: 0 0 30px rgba(0, 229, 255, 0.6);
79
+ transform: translateY(-3px);
80
+ }
81
+ .obsidian-panel {
82
+ border: 1px solid #111111 !important;
83
+ background: #050505 !important;
84
+ padding: 35px !important;
85
+ border-radius: 0px !important;
86
+ }
87
+ input, textarea {
88
+ background-color: #080808 !important;
89
+ border: 1px solid #1a1a1a !important;
90
+ color: #ffffff !important;
91
+ font-weight: 700 !important;
92
+ }
93
+ """
94
+
95
+ with gr.Blocks(css=titan_css, theme=gr.themes.Base()) as demo:
96
+ gr.Markdown("# LOGICFORGE", elem_id="main-header")
97
+ gr.Markdown("MUHAMMAD BILAL / SENIOR DEVELOPER", elem_id="dev-tag")
98
+ gr.HTML("<div class='glow-divider'></div>")
99
+
100
+ with gr.Row():
101
+ with gr.Column(scale=4, elem_classes="obsidian-panel"):
102
+ gr.Markdown("### 📡 NEURAL INPUT")
103
+ audio_input = gr.Audio(sources="microphone", type="filepath", label="Voice Stream")
104
+ submit_btn = gr.Button("INITIATE PROTOCOL", elem_classes="titan-btn")
105
+
106
+ with gr.Column(scale=6, elem_classes="obsidian-panel"):
107
+ gr.Markdown("### 🧠 LOGIC SYNTHESIS")
108
+ user_transcript = gr.Textbox(label="Raw Transcription")
109
+ ai_text_reply = gr.Textbox(label="Strategic Output")
110
+ audio_output = gr.Audio(label="Auditory Feedback", autoplay=True)
111
+
112
+ submit_btn.click(master_process, inputs=audio_input, outputs=[user_transcript, ai_text_reply, audio_output])
113
+
114
+ demo.launch()