Tanseer45203 commited on
Commit
2c5f657
·
verified ·
1 Parent(s): 5b86dbf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load API key
7
+ load_dotenv()
8
+ API_KEY = os.getenv("GROQ_API_KEY")
9
+
10
+ # Initialize Groq client
11
+ client = Groq(api_key=API_KEY)
12
+
13
+ # Streamlit App Title
14
+ st.title("🧠 Brain-to-Text AI Keyboard")
15
+
16
+ # User input: Simulated brain signal (text description)
17
+ st.subheader("Think of a sentence, then describe it in words:")
18
+ thought_input = st.text_area("Describe your thought:", height=100)
19
+
20
+ # Virtual keyboard (optional)
21
+ st.subheader("Or use the virtual keyboard to refine your thought:")
22
+ if "typed_text" not in st.session_state:
23
+ st.session_state.typed_text = ""
24
+
25
+ # Define keyboard layout
26
+ keyboard_layout = [
27
+ ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
28
+ ["A", "S", "D", "F", "G", "H", "J", "K", "L"],
29
+ ["Z", "X", "C", "V", "B", "N", "M", "←"],
30
+ ["Space"]
31
+ ]
32
+
33
+ # Display keyboard
34
+ for row in keyboard_layout:
35
+ cols = st.columns(len(row))
36
+ for i, key in enumerate(row):
37
+ if cols[i].button(key):
38
+ if key == "←":
39
+ st.session_state.typed_text = st.session_state.typed_text[:-1]
40
+ elif key == "Space":
41
+ st.session_state.typed_text += " "
42
+ else:
43
+ st.session_state.typed_text += key
44
+
45
+ # Display user-typed text
46
+ st.text_area("Refined Thought:", value=st.session_state.typed_text, height=100)
47
+
48
+ # Generate AI-based Brain-to-Text Conversion
49
+ if st.button("Convert Thought to Text"):
50
+ full_input = thought_input.strip() + " " + st.session_state.typed_text.strip()
51
+ if full_input.strip():
52
+ try:
53
+ response = client.chat.completions.create(
54
+ model="llama-3.3-70b-versatile",
55
+ messages=[{"role": "user", "content": full_input}]
56
+ )
57
+ st.write("### AI Interpreted Thought:")
58
+ st.write(response.choices[0].message.content)
59
+ except Exception as e:
60
+ st.error(f"Error: {e}")
61
+ else:
62
+ st.warning("Please describe a thought before converting.")