steve7909 commited on
Commit
a224a43
1 Parent(s): 5c9cb00

added anki sentence pairs

Browse files
anki_japanese_english_pairs.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py CHANGED
@@ -10,8 +10,12 @@ import requests
10
  import gradio as gr
11
  from dotenv import load_dotenv
12
  import os
13
- from openai import OpenAI
 
14
  import spacy
 
 
 
15
 
16
  # Load environment variables from .env file
17
  load_dotenv()
@@ -93,56 +97,18 @@ def translate_openai(input_text):
93
 
94
  return translation
95
 
96
- def assess(original_japanese, student_translation):
97
-
98
- try:
99
- # get the English translation
100
- generated_translation = translate_hf(original_japanese)
101
- debug_print("Generated translation:", generated_translation)
102
- except Exception as e:
103
- return "Error in processing translation.", str(e)
104
-
105
- try:
106
- prompt = (f"Evaluate the student's English translation of Japanese for accuracy and naturalness. "
107
- f"Original: {original_japanese}, "
108
- f"Reference Translation: {generated_translation}, "
109
- f"Student Translation: {student_translation}. "
110
- "Highlight errors, suggest improvements, and note any nuances. Provide concise and very simple feedback for an English language learner aimed at improving their translation skills. Where possible, give concrete examples.")
111
-
112
- debug_print(prompt)
113
-
114
- # Evaluating the student's translation attempt
115
- response = client.chat.completions.create(
116
- messages=[
117
- {
118
- "role": "user",
119
- "content": prompt,
120
- }
121
- ],
122
- model="gpt-3.5-turbo",
123
- )
124
 
125
- debug_print("Full GPT response:", response)
126
-
127
- debug_print("Generated translation:", generated_translation)
128
-
129
- evaluation_feedback = response.choices[0].message.content
130
-
131
- return generated_translation, evaluation_feedback
132
- except Exception as e:
133
- return "Error in processing evaluation.", str(e)
134
-
135
- assessor = gr.Interface(fn=assess,
136
- inputs=[
137
- gr.Textbox(label="Japanese Sentence Input", placeholder="Input text to be translated", lines=1, value="これは例です"),#example_Japanese),#"
138
- gr.Textbox(label="Student's Translation Attempt", placeholder="Input your English translation", lines=1, value="This is an example")#"This is an example")
139
- ],
140
- outputs=[
141
- gr.Textbox(label="Machine Generated Translation"),
142
- gr.Textbox(label="Evaluation Feedback")
143
- ],
144
- title="Translation Practice",
145
- description="Enter a Japanese sentence and your English translation attempt to receive evaluation feedback."
146
- )
147
-
148
- assessor.launch(debug=True, share=True)
 
10
  import gradio as gr
11
  from dotenv import load_dotenv
12
  import os
13
+ #from openai import OpenAI
14
+ from langchain_openai import OpenAI
15
  import spacy
16
+ #from langchain.chat_models import ChatOpenAI
17
+ from langchain_openai import ChatOpenAI
18
+ from langchain.schema import AIMessage, HumanMessage
19
 
20
  # Load environment variables from .env file
21
  load_dotenv()
 
97
 
98
  return translation
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
+ llm = ChatOpenAI(temperature=0.7, model='gpt-3.5-turbo')
102
+
103
+ def predict(message, history):
104
+ history_langchain_format = []
105
+ for human, ai in history:
106
+ history_langchain_format.append(HumanMessage(content=human)) # converted to str to avoid error; not compatible with multimodal
107
+ history_langchain_format.append(AIMessage(content=ai))
108
+ history_langchain_format.append(HumanMessage(content=message))
109
+ gpt_response = llm(history_langchain_format)
110
+ return gpt_response.content
111
+
112
+ app = gr.ChatInterface(fn=predict, title="Translation Chatbot")#, multimodal=True)
113
+
114
+ app.launch()
 
 
 
 
 
 
 
 
 
 
sentence_pairs.txt → sentence_pairs_dai.txt RENAMED
@@ -1,5 +1,5 @@
1
  「日本語の文法って難しい」と思っている人が多いのではないでしょうか。小学校や中学校の国語の文法の時間は退屈でしかたがなかったという思い出を持つ方も多いかと思います。, Japanese grammar is considered difficult, isn't it? I think many people had the experience that the grammar classes in preliminary schools or junior high schools were so boring.
2
- 大気中の二酸化炭素の量が増えていることが,地球温暖化を引き起こしている。,The increasement of carbon dioxide in the air is causing global warming.
3
  新メディアの登場で「紙」の新聞を購読する代わりに,パソコン画面に無料で提供されるニュース情報の閲読で済ます人々が年々増えてきた。,More and more people are consuming free web news instead of subscribing the printed news.
4
  日本は現在。退職した人々の生活を支える労働人口がますます減少しているという厳しい状況に直面している。,Japan is facing the lack of working labor to support the life expenditure of retired populations.
5
  閉店間際なので,スーパーではパンは売り切れているかもしれないと心配したが、運良く.まだ一斤残っていた。,I was worried that the bread was sold out when I entered the super market right before it closed. But luckily, I got the last one.
 
1
  「日本語の文法って難しい」と思っている人が多いのではないでしょうか。小学校や中学校の国語の文法の時間は退屈でしかたがなかったという思い出を持つ方も多いかと思います。, Japanese grammar is considered difficult, isn't it? I think many people had the experience that the grammar classes in preliminary schools or junior high schools were so boring.
2
+ 大気中の二酸化炭素の量が増えていることが,地球温暖化を引き起こしている。,The increase of carbon dioxide in the air is causing global warming.
3
  新メディアの登場で「紙」の新聞を購読する代わりに,パソコン画面に無料で提供されるニュース情報の閲読で済ます人々が年々増えてきた。,More and more people are consuming free web news instead of subscribing the printed news.
4
  日本は現在。退職した人々の生活を支える労働人口がますます減少しているという厳しい状況に直面している。,Japan is facing the lack of working labor to support the life expenditure of retired populations.
5
  閉店間際なので,スーパーではパンは売り切れているかもしれないと心配したが、運良く.まだ一斤残っていた。,I was worried that the bread was sold out when I entered the super market right before it closed. But luckily, I got the last one.