CineAI commited on
Commit
9d6bb51
·
verified ·
1 Parent(s): df8fe22

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +89 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,91 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ # --- Page Configuration ---
4
+ st.set_page_config(
5
+ page_title="Keyboard Layout Fixer",
6
+ page_icon="⌨️",
7
+ layout="centered",
8
+ )
9
+
10
+ # --- Image and Title ---
11
+ # Display the keyboard image you provided
12
+ st.image(
13
+ "https://i.imgur.com/kQoK6c9.png",
14
+ caption="Apple Magic Keyboard with Ukrainian/English Layout"
15
+ )
16
+
17
+ st.title("⌨️ Keyboard Layout Fixer")
18
+ st.markdown(
19
+ """
20
+ Ever typed a whole sentence only to realize you forgot to switch keyboard layouts? 🤦
21
+ For example, typing `руддщ` instead of `hello`.
22
+
23
+ This simple tool instantly converts text typed in the wrong layout between **Ukrainian** and **English**.
24
+ """
25
+ )
26
+
27
+ # --- Translation Dictionaries and Function ---
28
+
29
+ # Provided Ukrainian to English layout map
30
+ ukr_to_eng_keyboard_layout = {
31
+ 'й': 'q', 'ц': 'w', 'у': 'e', 'к': 'r', 'е': 't', 'н': 'y', 'г': 'u', 'ш': 'i', 'щ': 'o', 'з': 'p', 'х': '[', 'ї': ']', 'ф': 'a', 'і': 's', 'в': 'd', 'а': 'f', 'п': 'g', 'р': 'h', 'о': 'j', 'л': 'k', 'д': 'l', 'ж': ';', 'є': "'", 'я': 'z', 'ч': 'x', 'с': 'c', 'м': 'v', 'и': 'b', 'т': 'n', 'ь': 'm', 'б': ',', 'ю': '.',
32
+ 'Й': 'Q', 'Ц': 'W', 'У': 'E', 'К': 'R', 'Е': 'T', 'Н': 'Y', 'Г': 'U', 'Ш': 'I', 'Щ': 'O', 'З': 'P', 'Х': '{', 'Ї': '}', 'Ф': 'A', 'І': 'S', 'В': 'D', 'А': 'F', 'П': 'G', 'Р': 'H', 'О': 'J', 'Л': 'K', 'Д': 'L', 'Ж': ':', 'Є': '"', 'Я': 'Z', 'Ч': 'X', 'С': 'C', 'М': 'V', 'И': 'B', 'Т': 'N', 'Ь': 'M', 'Б': '<', 'Ю': '>',
33
+ "'": '`', '₴': '~', '.': '/', ',': '?'
34
+ }
35
+
36
+ # Create the reverse map for English to Ukrainian
37
+ eng_to_ukr_keyboard_layout = {v: k for k, v in ukr_to_eng_keyboard_layout.items()}
38
+
39
+ def fix_layout(text, layout_map):
40
+ """
41
+ Translates text from one keyboard layout to another using a dictionary.
42
+ """
43
+ # Use a list comprehension and join for a more efficient implementation
44
+ return "".join([layout_map.get(char, char) for char in text])
45
+
46
+ # --- Sidebar for Options ---
47
+ st.sidebar.header("Settings")
48
+ direction = st.sidebar.radio(
49
+ "Choose conversion direction:",
50
+ ("🇺🇦 Ukrainian → 🇬🇧 English", "🇬🇧 English → 🇺🇦 Ukrainian"),
51
+ key="direction_radio"
52
+ )
53
+
54
+ # --- Main App Interface ---
55
+ st.header("Input")
56
+
57
+ # Choose the appropriate label and placeholder based on the direction
58
+ if direction == "🇺🇦 Ukrainian → 🇬🇧 English":
59
+ input_label = "Enter text typed in Ukrainian layout (that was meant to be English):"
60
+ placeholder_text = "руддщ, цщкдв!" # Intended: "hello, world!"
61
+ layout_map = ukr_to_eng_keyboard_layout
62
+ else:
63
+ input_label = "Enter text typed in English layout (that was meant to be Ukrainian):"
64
+ placeholder_text = "ghbdsn, cdsn!" # Intended: "привіт, світ!"
65
+ layout_map = eng_to_ukr_keyboard_layout
66
+
67
+ # Text area for user input
68
+ original_text = st.text_area(
69
+ label=input_label,
70
+ value="",
71
+ placeholder=f"e.g., '{placeholder_text}'",
72
+ height=150,
73
+ key="input_text_area"
74
+ )
75
+
76
+ # --- Translation Logic and Output ---
77
+ if original_text:
78
+ translated_text = fix_layout(original_text, layout_map)
79
+
80
+ st.header("Result")
81
+ st.code(translated_text, language=None)
82
+
83
+ # Simple copy "instruction"
84
+ st.info("The result text is displayed in the box above for easy copying.")
85
+
86
+ else:
87
+ st.info("Enter some text in the box above to see the conversion.")
88
+
89
+ # --- Footer ---
90
+ st.markdown("---")
91
+ st.markdown("Made with ❤️ using [Streamlit](https://streamlit.io).")