updated prompt wording issue
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ import spacy
|
|
9 |
from langchain_openai import ChatOpenAI
|
10 |
from langchain.schema import AIMessage, HumanMessage
|
11 |
import pandas as pd
|
|
|
|
|
12 |
|
13 |
# Load environment variables from .env file
|
14 |
load_dotenv()
|
@@ -16,6 +18,8 @@ load_dotenv()
|
|
16 |
# Access the env
|
17 |
HF_TOKEN = os.getenv('HUGGING_FACE_TOKEN')
|
18 |
|
|
|
|
|
19 |
# openai setup
|
20 |
# client = OpenAI(
|
21 |
# api_key=os.getenv('OPENAI_API_KEY')
|
@@ -30,6 +34,29 @@ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
|
30 |
# Global variable to control debug printing
|
31 |
DEBUG_MODE = True
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def debug_print(*args, **kwargs):
|
34 |
if DEBUG_MODE:
|
35 |
print(*args, **kwargs)
|
@@ -82,7 +109,7 @@ def predict(message, history):
|
|
82 |
Encourage the student by specifying the strengths of their writing.
|
83 |
DO NOT PROVIDE THE CORRECT ENGLISH TRANSLATION until the student gets the correct translation. Let the student work it out.
|
84 |
Provide your feedback as a list in the format: a, b, c etc.
|
85 |
-
Do not respond in Japanese - always respond in English even if the student uses Japanese
|
86 |
|
87 |
Execute the following tasks step by step:
|
88 |
1. Ask the student to translate the following sentence from Japanese to English: {japanese_sentence}. Here is the English translation for reference: {english_sentence}
|
@@ -109,10 +136,16 @@ def predict(message, history):
|
|
109 |
|
110 |
#debug_print("### Full history: ", history_langchain_format)
|
111 |
gpt_response = llm(history_langchain_format)
|
112 |
-
return
|
113 |
|
114 |
welcome_message = "Hi! ๐. Are you ready to practise translation?"
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
app = gr.ChatInterface(fn=predict, title="Translation Chatbot", chatbot=gr.Chatbot(value=[(None, welcome_message)],),)#, multimodal=True) # chatbot=gr.Chatbot(value=[["Welcome ๐. I am an assistant",]])
|
117 |
|
118 |
|
|
|
9 |
from langchain_openai import ChatOpenAI
|
10 |
from langchain.schema import AIMessage, HumanMessage
|
11 |
import pandas as pd
|
12 |
+
import uuid
|
13 |
+
import json
|
14 |
|
15 |
# Load environment variables from .env file
|
16 |
load_dotenv()
|
|
|
18 |
# Access the env
|
19 |
HF_TOKEN = os.getenv('HUGGING_FACE_TOKEN')
|
20 |
|
21 |
+
GITHUB_TOKEN = "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" # move to env
|
22 |
+
|
23 |
# openai setup
|
24 |
# client = OpenAI(
|
25 |
# api_key=os.getenv('OPENAI_API_KEY')
|
|
|
34 |
# Global variable to control debug printing
|
35 |
DEBUG_MODE = True
|
36 |
|
37 |
+
|
38 |
+
def share_to_gist(content, public=False):
|
39 |
+
url = "https://api.github.com/gists"
|
40 |
+
headers = {
|
41 |
+
"Authorization": f"token {os.getenv(GITHUB_TOKEN)}",
|
42 |
+
"Accept": "application/vnd.github.v3+json",
|
43 |
+
}
|
44 |
+
data = {
|
45 |
+
"public": public,
|
46 |
+
"description": "Chat history",
|
47 |
+
"files": {
|
48 |
+
"chat.txt": {
|
49 |
+
"content": content
|
50 |
+
}
|
51 |
+
}
|
52 |
+
}
|
53 |
+
response = requests.post(url, headers=headers, data=json.dumps(data))
|
54 |
+
gist_url = response.json().get('html_url', '')
|
55 |
+
return gist_url
|
56 |
+
|
57 |
+
def generate_unique_id():
|
58 |
+
return str(uuid.uuid4())
|
59 |
+
|
60 |
def debug_print(*args, **kwargs):
|
61 |
if DEBUG_MODE:
|
62 |
print(*args, **kwargs)
|
|
|
109 |
Encourage the student by specifying the strengths of their writing.
|
110 |
DO NOT PROVIDE THE CORRECT ENGLISH TRANSLATION until the student gets the correct translation. Let the student work it out.
|
111 |
Provide your feedback as a list in the format: a, b, c etc.
|
112 |
+
Do not respond in Japanese - always respond in English even if the student uses Japanese with you.
|
113 |
|
114 |
Execute the following tasks step by step:
|
115 |
1. Ask the student to translate the following sentence from Japanese to English: {japanese_sentence}. Here is the English translation for reference: {english_sentence}
|
|
|
136 |
|
137 |
#debug_print("### Full history: ", history_langchain_format)
|
138 |
gpt_response = llm(history_langchain_format)
|
139 |
+
return gpt_response.content
|
140 |
|
141 |
welcome_message = "Hi! ๐. Are you ready to practise translation?"
|
142 |
|
143 |
+
# with gr.Blocks() as app:
|
144 |
+
# chatbot = gr.Chatbot()
|
145 |
+
# message = gr.Textbox()
|
146 |
+
# clear = gr.ClearButton([message, chatbot])
|
147 |
+
# message.submit(predict, [message, chatbot], [message, chatbot])
|
148 |
+
|
149 |
app = gr.ChatInterface(fn=predict, title="Translation Chatbot", chatbot=gr.Chatbot(value=[(None, welcome_message)],),)#, multimodal=True) # chatbot=gr.Chatbot(value=[["Welcome ๐. I am an assistant",]])
|
150 |
|
151 |
|