Aidan Phillips
commited on
Commit
Β·
eece69a
1
Parent(s):
c2756e2
clean sidebar + scoring
Browse files- .streamlit/config.toml +2 -0
- app.py +15 -8
- modules/nav.py +15 -0
- pages/2_Scoring.py +0 -0
- pages/scoring.py +28 -0
- pages/{1_ EN-DE.py β to_german.py} +0 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[client]
|
2 |
+
showSidebarNavigation = false
|
app.py
CHANGED
@@ -7,9 +7,11 @@ from categories.accuracy import *
|
|
7 |
from categories.fluency import *
|
8 |
import random
|
9 |
|
10 |
-
|
11 |
-
st.sidebar.title("DE-EN")
|
12 |
|
|
|
|
|
|
|
13 |
def load_translations():
|
14 |
try:
|
15 |
with open("./translations.json", "r") as f:
|
@@ -18,9 +20,11 @@ def load_translations():
|
|
18 |
print(e)
|
19 |
return None
|
20 |
|
|
|
21 |
if "translations" not in st.session_state:
|
22 |
st.session_state.translations = load_translations()
|
23 |
|
|
|
24 |
def response_generator(prompt):
|
25 |
source = st.session_state.german
|
26 |
acc = accuracy(source, prompt)
|
@@ -29,6 +33,10 @@ def response_generator(prompt):
|
|
29 |
|
30 |
total_score = 0.5 * acc["score"] + 0.2 * gre["score"] + 0.3 * ppl["score"]
|
31 |
|
|
|
|
|
|
|
|
|
32 |
response = "Your total translation score is: " + str(total_score) + "\n"
|
33 |
|
34 |
acc_s = acc["score"]
|
@@ -36,14 +44,14 @@ def response_generator(prompt):
|
|
36 |
|
37 |
for error in acc["errors"]:
|
38 |
response += f" - {error['message']}\n"
|
39 |
-
|
40 |
gre_s = gre["score"]
|
41 |
ppl_s = ppl["score"]
|
42 |
response += f"\nYour fluency score is {0.4 * gre_s + 0.6 * ppl_s}:\n"
|
43 |
|
44 |
for error in gre["errors"]:
|
45 |
response += f" - {error['message']}\n"
|
46 |
-
|
47 |
for error in ppl["errors"]:
|
48 |
response += f" - {error['message']}\n"
|
49 |
|
@@ -65,7 +73,6 @@ def translation_generator():
|
|
65 |
st.error("No translations available.")
|
66 |
return
|
67 |
|
68 |
-
|
69 |
message = (
|
70 |
f"Please translate the following sentence into English:"
|
71 |
f" {st.session_state.german}"
|
@@ -80,8 +87,6 @@ def translation_generator():
|
|
80 |
yield "\n"
|
81 |
|
82 |
|
83 |
-
st.title("Translation bot")
|
84 |
-
|
85 |
# Initialize chat history
|
86 |
if "messages" not in st.session_state:
|
87 |
st.session_state.messages = [
|
@@ -103,7 +108,9 @@ if "translations" not in st.session_state:
|
|
103 |
except (FileNotFoundError, json.JSONDecodeError):
|
104 |
st.session_state.translations = None
|
105 |
# Create an empty translations dictionary if none exists
|
106 |
-
st.error(
|
|
|
|
|
107 |
|
108 |
# Display chat messages from history on app rerun
|
109 |
for message in st.session_state.messages:
|
|
|
7 |
from categories.fluency import *
|
8 |
import random
|
9 |
|
10 |
+
from modules.nav import Navbar
|
|
|
11 |
|
12 |
+
Navbar()
|
13 |
+
|
14 |
+
# Load translations from a JSON file to be used by the bot
|
15 |
def load_translations():
|
16 |
try:
|
17 |
with open("./translations.json", "r") as f:
|
|
|
20 |
print(e)
|
21 |
return None
|
22 |
|
23 |
+
|
24 |
if "translations" not in st.session_state:
|
25 |
st.session_state.translations = load_translations()
|
26 |
|
27 |
+
|
28 |
def response_generator(prompt):
|
29 |
source = st.session_state.german
|
30 |
acc = accuracy(source, prompt)
|
|
|
33 |
|
34 |
total_score = 0.5 * acc["score"] + 0.2 * gre["score"] + 0.3 * ppl["score"]
|
35 |
|
36 |
+
if "scores" not in st.session_state:
|
37 |
+
st.session_state.scores = []
|
38 |
+
st.session_state.scores.append(total_score)
|
39 |
+
|
40 |
response = "Your total translation score is: " + str(total_score) + "\n"
|
41 |
|
42 |
acc_s = acc["score"]
|
|
|
44 |
|
45 |
for error in acc["errors"]:
|
46 |
response += f" - {error['message']}\n"
|
47 |
+
|
48 |
gre_s = gre["score"]
|
49 |
ppl_s = ppl["score"]
|
50 |
response += f"\nYour fluency score is {0.4 * gre_s + 0.6 * ppl_s}:\n"
|
51 |
|
52 |
for error in gre["errors"]:
|
53 |
response += f" - {error['message']}\n"
|
54 |
+
|
55 |
for error in ppl["errors"]:
|
56 |
response += f" - {error['message']}\n"
|
57 |
|
|
|
73 |
st.error("No translations available.")
|
74 |
return
|
75 |
|
|
|
76 |
message = (
|
77 |
f"Please translate the following sentence into English:"
|
78 |
f" {st.session_state.german}"
|
|
|
87 |
yield "\n"
|
88 |
|
89 |
|
|
|
|
|
90 |
# Initialize chat history
|
91 |
if "messages" not in st.session_state:
|
92 |
st.session_state.messages = [
|
|
|
108 |
except (FileNotFoundError, json.JSONDecodeError):
|
109 |
st.session_state.translations = None
|
110 |
# Create an empty translations dictionary if none exists
|
111 |
+
st.error(
|
112 |
+
"No previous translations found. Starting with an empty translation history."
|
113 |
+
)
|
114 |
|
115 |
# Display chat messages from history on app rerun
|
116 |
for message in st.session_state.messages:
|
modules/nav.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def Navbar():
|
4 |
+
with st.sidebar:
|
5 |
+
st.title("Der Roboterlehrer")
|
6 |
+
st.markdown("### Translation Bots")
|
7 |
+
st.page_link('app.py', label='German to English', icon="π©πͺ")
|
8 |
+
st.page_link('pages/to_german.py', label='English to German', icon="π¬π§")
|
9 |
+
st.markdown("### Analysis")
|
10 |
+
st.page_link('pages/scoring.py', label='Score Analysis', icon="π")
|
11 |
+
st.divider()
|
12 |
+
st.markdown("### About")
|
13 |
+
st.markdown(
|
14 |
+
"This app is a translation bot that helps you practice your language skills. It uses machine learning models to evaluate your translations and provide feedback."
|
15 |
+
)
|
pages/2_Scoring.py
DELETED
File without changes
|
pages/scoring.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
from modules.nav import Navbar
|
6 |
+
|
7 |
+
Navbar()
|
8 |
+
|
9 |
+
# Set page title
|
10 |
+
st.title("Score Analysis")
|
11 |
+
|
12 |
+
# Initialize session state for scores if it doesn't exist
|
13 |
+
if 'scores' not in st.session_state:
|
14 |
+
st.session_state.scores = []
|
15 |
+
|
16 |
+
# Display scores if they exist
|
17 |
+
if st.session_state.scores:
|
18 |
+
# Calculate average
|
19 |
+
average_score = np.mean(st.session_state.scores)
|
20 |
+
|
21 |
+
if average_score > 90:
|
22 |
+
st.balloons()
|
23 |
+
|
24 |
+
# Display the average
|
25 |
+
st.header("Score Results")
|
26 |
+
st.metric(label="Average Score", value=f"{average_score:.2f}")
|
27 |
+
else:
|
28 |
+
st.info("No scores have been entered yet. Please chat with the bot first!")
|
pages/{1_ EN-DE.py β to_german.py}
RENAMED
File without changes
|