jetaimejeteveux commited on
Commit
4fc0d2a
1 Parent(s): fa9c5e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +381 -0
app.py ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import torch
4
+ from auto_gptq import AutoGPTQForCausalLM
5
+ from langchain.chains import ConversationalRetrievalChain
6
+ from langchain.chains.question_answering import load_qa_chain
7
+ from langchain.document_loaders import DirectoryLoader
8
+ from langchain.embeddings import HuggingFaceEmbeddings
9
+ from langchain.llms import HuggingFacePipeline
10
+ from langchain.memory import ConversationBufferMemory
11
+ from langchain.prompts import PromptTemplate
12
+ from langchain.text_splitter import CharacterTextSplitter
13
+ from langchain.vectorstores import Chroma
14
+ from transformers import AutoTokenizer, GenerationConfig, TextStreamer, pipeline
15
+ import gradio as gr
16
+
17
+ questions_dir = Path("global-korea-scholarship")
18
+ def write_file(question, answer, file_path):
19
+ text = f"""
20
+ Q:{question}
21
+ A:{answer}
22
+ """.strip()
23
+ with Path(questions_dir / file_path).open("w") as text_files:
24
+ text_files.write(text)
25
+
26
+ write_file(
27
+ question="Should I submit my parents’ passport copy?",
28
+ answer="It is necessary to submit an official document (i.e., applicant’s birth certificate or family register) that proves you and your parents’ relationship. If the document does not include you and your parents’ citizenship information, then you should submit additional documents (i.e., passport copy or other government issued document that indicates citizenship information) for proof of citizenship. Please note that a birth place or ethnic group information on a birth certificate or current residency in the submitted documents will not be accepted as a proof of citizenship.",
29
+ file_path="question_1.txt",
30
+ )
31
+
32
+ write_file(
33
+ question="My father has deceased long time ago, and I cannot provide his proof of citizenship.",
34
+ answer="If you are not able to issue your parent(s)’ proof of citizenship due to your parent(s)’ absence (e.g., divorced, deceased, etc.), then please provide supplementary documents that explains the reason for not submitting their proof of citizenship. (e.g., divorce certificate or death certificate).",
35
+ file_path="question_2.txt",
36
+ )
37
+
38
+ write_file(
39
+ question="My parents and I hold different citizenship. Am I eligible to apply for the program?",
40
+ answer="Yes you may. As long as you and your parent(s) do not hold Korean citizenship, and if you have a citizenship of the country that is invited to the GKS degree program, you are eligible to apply.",
41
+ file_path="question_3.txt",
42
+ )
43
+
44
+ write_file(
45
+ question="My country is not listed in the 2023 GSK-G program. Can I apply for the program?",
46
+ answer="The quota allocation is decided based on mutual agreements on cultural and educational cooperation between Korea and the participating countries. All applicants must hold a citizenship of the GKS partner country except for the R&D program. R&D program is open to all countries around the world. R&D program applicants must directly apply to their designated universities since the program is only available under a university track.",
47
+ file_path="question_4.txt",
48
+ )
49
+
50
+ write_file(
51
+ question="I am expected to graduate from my degree program in March 2024. Am I eligible to apply for this program?",
52
+ answer="Yes. Applicants who are expected to graduate by July 31st, 2024 can also apply for the program with a certificate of expected graduation. Such applicants must submit their official graduation certificate (or diploma) and final academic transcript to GKS Center, NIIED by July 31st, 2024. Failure to do so will result in the cancellation of your acceptance.",
53
+ file_path="question_5.txt",
54
+ )
55
+
56
+ write_file(
57
+ question="I have a master’s degree. Can I apply for a master’s degree program in a different major? Which degree certificate should I submit?",
58
+ answer="You can apply for a master’s program while holding another master’s degree. If you are applying to a master’s degree program, you should submit a degree certificate and academic transcript of your bachelor’s degree. In this case, your CGPA of your bachelor’s degree should meet the grade requirement in the application guidelines. Providing your master’s degree certificate and academic transcript is optional.",
59
+ file_path="question_6.txt",
60
+ )
61
+
62
+ write_file(
63
+ question="I am currently in my master’s degree program at a university in Korea. Am I eligible to apply for the master’s degree program at another university?",
64
+ answer="If you have graduated from a Korean high school or a Korean university, or if are currently enrolled in the final year of your degree curriculum (or if you are about to obtain a degree) at a Korean University, you cannot apply for the GKS degree program. If you are not near the graduation, you may apply for the program. However, if you are selected as our GKS scholar, you must drop out of the Korean university you are currently enrolled at and start the degree program under GKS as a first year. Transfer credits from your previous university will not be accepted. Applicants who are residing in Korea may need to return to their own country in order to issue a new visa for their Korean language program/degree program. In this case, their entry airfare will not be provided.",
65
+ file_path="question_7.txt",
66
+ )
67
+
68
+ write_file(
69
+ question="The grades in my transcript are different from the GPA scales in the guidelines. How should I submit my CGPA? Can I use the scores I converted from a grade conversion website?",
70
+ answer="If your grades do not belong to any of the GPA scales we accept (4.0, 4.3, 4.5, 5.0 or 100 point scale), you must submit a converted grade confirmed by the university. If applicants convert their grades through a grade conversion tool such as scholaro.com, the converted CGPA must be officially acknowledged by the relevant university. Please submit an official certificate or at least a testimonial issued by your university that confirms the converted CGPA. This supplementary document does not need to be apostilled or consular confirmed but must be submitted in an original document with the university’s authentication. The screening committee will determine whether your CGPA is eligible for the program or not based on the information you provide.",
71
+ file_path="question_8.txt",
72
+ )
73
+
74
+ write_file(
75
+ question="My CGPA is below 80%. Am I not eligible to apply for the program?",
76
+ answer="You are eligible to apply if you are ranked within the top 20% of your class even if your score percentile is below 80%. Along with your original transcript, please submit an official certificate or a letter from your university that your grade stands within the top 20% of your class.",
77
+ file_path="question_9.txt",
78
+ )
79
+
80
+ write_file(
81
+ question="My academic transcript only indicates CGPA and does not offer GPA by semester. What should I put in the application form?",
82
+ answer="If your transcript does not provide GPA of each semester/year, you do not need to fill in the box for each semester/year. However, you must put your CGPA AND a score percentile of the entire degree curriculum. If your transcript does not provide a score percentile, refer to Appendix “GPA Conversion Table” to convert your CGPA into a 100 point scale.",
83
+ file_path="question_10.txt",
84
+ )
85
+
86
+ write_file(
87
+ question="I am applying for a doctoral degree program. Should I also submit a CGPA of my bachelor’s degree?",
88
+ answer="Applicants for a doctoral degree program should put a CGPA of their previous degree (master’s degree) on the application form. Doctoral degree program applicants should submit the graduation certificate and official academic transcript of both bachelor’s and master’s degree. The CGPA required in the application is of the master’s degree.",
89
+ file_path="question_11.txt",
90
+ )
91
+
92
+ write_file(
93
+ question="I transferred to my university, but the official academic transcript issued by my university does not indicate the GPA of my previous university. How should I submit my academic record?",
94
+ answer="Please submit an official academic transcript issued by the university you graduated from. If the transcript does not indicate your grades of the entire degree curriculum, please submit your academic records of the previous university as a supplementary document as a reference material. The CGPA required in the application should be the one shown on the official academic transcript from the university you have graduated from.",
95
+ file_path="question_12.txt",
96
+ )
97
+
98
+ write_file(
99
+ question="I meet all the application requirements listed in the application guideline. Does this mean that I am qualified to apply to all GKS partner universities?",
100
+ answer="Not necessarily. The application requirements we have indicated in the application guideline are the minimum requirements to apply for the GKS program. Some universities and departments may have additional requirements such as certain level of language proficiency. Therefore, we ask all prospective applicants to check the “University information” files posted with the application guideline to find required qualifications set by each university/department. If a university requests additional material (e.g., portfolio) beyond NIIED’s required documents, you should submit those materials directly to the university.",
101
+ file_path="question_13.txt",
102
+ )
103
+
104
+ write_file(
105
+ question="I am currently living in Korea. Can I apply for this program?",
106
+ answer="Yes, you may apply for the program while residing in a different country. Applicants must apply either through a Korean embassy where they hold citizenship (embassy track) or through a Korean university (university track). Embassy track applicants who are applying from a third country must check the method of application submission or interview process with the embassy. Successful candidates who are currently residing in Korea or enter Korea from a third country will not be provided with the entry airfare. Please be noted that it may take more time and effort to obtain necessary authentications (apostille, consular confirmation, certified translation, etc.) on required documents from abroad.",
107
+ file_path="question_14.txt",
108
+ )
109
+
110
+ write_file(
111
+ question="May I apply for the program by submitting my application to NIIED directly?",
112
+ answer="No, you may not. Applicants must submit their application documents to the GKS selection department at a Korean embassy or a university they are applying to. NIIED only accepts applications from embassies or universities through official documents and does not accept applications from individual applicants. Any documents mistakenly sent to NIIED will be excluded from the screening and will not be returned.",
113
+ file_path="question_15.txt",
114
+ )
115
+
116
+ write_file(
117
+ question="When is the deadline for the application?",
118
+ answer="Each embassy/university has different application period. Please check the website of each institution to find out the application deadline. Embassies and universities that conduct the first round of selection have different application submission guidelines, so please check with the embassy/university regarding any submission related inquiries such as application deadline, submission method, etc.",
119
+ file_path="question_16.txt",
120
+ )
121
+
122
+ write_file(
123
+ question="I am a citizen of China/Czech Republic. In the application guidelines, there is quota only assigned in the embassy track for the Chinese/Czech citizens. Does that mean that I must apply to the Korean Embassy in my country?",
124
+ answer="If you are a Chinese citizen, you should submit your applications to China Scholarship Council (CSC) under the Ministry of Education in China instead of the Korean Embassy in China. This is based on the mutual agreement between Korean and China. Likewise, a Czech citizen must also submit the application to the Ministry of Education in Czech Republic, in accordance with the mutual agreement between the governments of Korea and Czech Republic.",
125
+ file_path="question_17.txt",
126
+ )
127
+
128
+ write_file(
129
+ question="I am a U.S. citizen living in Los Angeles. I am going to apply through an embassy track. Can I submit my application to the Korean Consulate in L.A. instead of the Korean Embassy in Washington D.C.?",
130
+ answer="Applicants from the United States of America and Vietnam can submit their application to the nearby Korean consulate. Korean embassy in Washington and Korean consulate in L.A. will cooperate to conduct the first round of selection. Please contact the Korean embassy for further information. Embassy track applicants in Vietnam can also submit their application documents to embassy/consulate in Hanoi, Danang, or Ho Chi Minh.",
131
+ file_path="question_18.txt",
132
+ )
133
+
134
+ write_file(
135
+ question="For the legalization on “Required certificates”, can I choose between apostille or consular confirmation?",
136
+ answer="Countries that have joined the Apostille Convention, can only issue an apostille. For the rest of the countries, you should obtain consular confirmation from the Korean embassy/consulate in your country. If your country does not belong to the Apostille Convention or if the document cannot be apostilled, please obtain a consular confirmation from the Korean embassy /consulate.",
137
+ file_path="question_19.txt",
138
+ )
139
+
140
+ write_file(
141
+ question="Can I submit an original degree certificate and academic transcript without apostille/consular confirmation?",
142
+ answer="The “Required certificates” must be submitted with an apostille or consular confirmation. Original documents without additional authentication, notarized documents certified by only a notary public, or certified documents confirmed by the other government agencies will not be accepted. (Exception: certificate issued by Korean government or institutions should be submitted in their original version without additional authentication.)",
143
+ file_path="question_20.txt",
144
+ )
145
+
146
+ write_file(
147
+ question="[Embassy track applicant] Should I apostille my birth certificate four times?",
148
+ answer="Embassy track applicants should submit ONE set of original application documents (that includes apostilled/consular-confirmed documents) and THREE sets of photocopied application documents. Therefore, embassy track applicants do not need to have their certificates authenticated four times.",
149
+ file_path="question_21.txt",
150
+ )
151
+
152
+ write_file(
153
+ question="I obtained an apostille on my graduation certificate in the past. Can I submit a copy of this document?",
154
+ answer="It will not be accepted as the document will be considered as a simple photocopy. It does not matter whether it is photocopied in color or black and white. Your document will be accepted only if the government agency that initially issued the apostille issues a certified true copy or if you obtain a certified true copy (등본인증) of your document from a Korean embassy.",
155
+ file_path="question_22.txt",
156
+ )
157
+
158
+ write_file(
159
+ question="How should I submit the documents with translation?",
160
+ answer="All application documents that are not written in Korean or English must be accompanied with a certified translation. For “Required certificates”, apostille or consular confirmation is only required either on original documents or on certified translations. If the document is written in both languages (original language and English), it does not need to be translated again.",
161
+ file_path="question_23.txt",
162
+ )
163
+
164
+ write_file(
165
+ question="I will submit my original graduation certificate with an apostille but it cannot be reissued any more. Can it be returned?",
166
+ answer="All application materials submitted to NIIED WILL NOT BE RETURNED IN ANY CASE. Please obtain an apostille or consular confirmation on a certified copy. If you do not pass the first round of selection, the embassy/university may (or may not) return your documents based on their policy. Please note that the graduation certificate submitted at the time of application will only be used for the selection procedure. Therefore, selected GKS scholars should prepare additional graduation certificates with an apostille/consular confirmation so they can submit it to different institutions to apply for a visa (embassy), to apply for a standard admission letter (university), or to change visa type (Korean immigration office) in the future.",
167
+ file_path="question_24.txt",
168
+ )
169
+
170
+ write_file(
171
+ question="I am curious about the validity of the authenticated documents. Can I submit my graduation certificate that was apostilled last year?",
172
+ answer="If there is an expiration date on an apostilled or consular confirmed document, the validity of the document will be judged based on the date indicated on the authentication. If there is no specific date indicated, the document will be accepted if it was submitted within 2 years from the date of authentication.",
173
+ file_path="question_25.txt",
174
+ )
175
+
176
+ write_file(
177
+ question="I have graduated from another country. Therefore, I cannot obtain an apostille on my certificates from my government or apply for a consular confirmation from the Korean embassy in my country. How should I submit my graduation certificate and academic transcript that were issued from another country?",
178
+ answer="If your documents were issued from the university or from a government abroad, you should obtain an apostille if the relevant country is a member of the Apostille Convention. If you are not able to obtain an apostille from abroad, please check if you can obtain a consular confirmation from the embassy/consulate of the relevant country.",
179
+ file_path="question_26.txt",
180
+ )
181
+
182
+ write_file(
183
+ question="How many departments and universities can I apply for admission?",
184
+ answer="If you apply through a university track, you may choose only ONE university and ONE department. If you apply through an embassy track, you may choose up to THREE universities under Type A and B. Please remember that at least one of your choices must be from Type B universities. Please note that you may choose the same department for all three universities, but cannot choose three different departments from a single university.",
185
+ file_path="question_27.txt",
186
+ )
187
+
188
+ write_file(
189
+ question="Are there tips on choosing three universities?",
190
+ answer="Embassy track applicants should understand that passing the second round of selection will not guarantee an admission to the university that you have chosen. Embassy track applicants who only choose highly competitive universities can fail from all three universities in the third round of selection. Each Korean university has recognition for variety of fields and has its own strength. Please conduct your own research to find out which university is the leading institution in the field of study you would like to pursue. Please also consider the fact that the cost of living for students at universities in the metropolitan area is higher than those in non-metropolitan universities. For your reference, GKS scholars pay for their accommodation within the stipend they receive each month.",
191
+ file_path="question_28.txt",
192
+ )
193
+
194
+ write_file(
195
+ question="Who should I obtain my recommendation letter from?",
196
+ answer="We recommend you receive your recommendation letter from someone who can provide thorough assessment of your academic abilities such as a professor or a dean of the department at your previous university. The recommendation letter should be dated within a year from the last date of the application deadline. Applicants who prepared their recommendation letter in advance may use the previous year’s (2022) recommendation letter form. Only one recommendation letter is required, but applicants may submit up to two recommendation letters if necessary.",
197
+ file_path="question_29.txt",
198
+ )
199
+
200
+ write_file(
201
+ question="Must I submit the certificates of language proficiency (English or Korean)?",
202
+ answer="The certificate of English proficiency (TOEIC, TOEFL, IELTS) or Korean proficiency (TOPIK) is optional, which means you may apply for GKS without it. However, some universities or departments may request applicants with certain level of language proficiency. It is helpful to provide supporting documentation that proves your abilities, including language skills. A proof that English was used as a medium of instruction cannot be a substitute for an English proficiency test certificate.",
203
+ file_path="question_30.txt",
204
+ )
205
+
206
+ write_file(
207
+ question="Should I include a detailed research proposal in the Study Plan?",
208
+ answer="Yes. You must at least describe the general direction and outlines of your study plans, if not in full detail. Please elaborate on your study objectives in Korea, tangible plans during and after you complete the degree program.",
209
+ file_path="question_31.txt",
210
+ )
211
+
212
+ write_file(
213
+ question="I am planning to apply through a university track. Can I submit my application to multiple universities?",
214
+ answer="University track applicants can only apply to one university and one department. If an applicant is found to have applied to more than two universities, his/her application document will be excluded from the next round of evaluation. Even after the announcement of qualified applicants, scholarships may be cancelled. Embassy track applicants whose application have not passed the first round may apply to a university track once more. However, applicants cannot apply for both tracks at once.",
215
+ file_path="question_32.txt",
216
+ )
217
+
218
+ write_file(
219
+ question="My name on my birth certificate is different from the one on my graduation certificate. What should I do when the names are different on the documents?",
220
+ answer="Applicant must apply with the name on their passport. If the name on your passport is different from other documents, please provide a supplementary document issued by your government that explains the discrepancy.",
221
+ file_path="question_33.txt",
222
+ )
223
+
224
+ write_file(
225
+ question="How will I know if I have passed each assessment?",
226
+ answer="Result of the first round of selection will be announced by each embassy and university. Result of the second round and the list of final successful candidates will be announced on the GKS Notice board at studyinkorea.go.kr website. Important notices for all applicants will be released on the GKS Notice board, so all applicants must check the website during the selection period.",
227
+ file_path="question_34.txt",
228
+ )
229
+
230
+ write_file(
231
+ question="Is it mandatory for all GKS scholars to pass at least Level 3 in TOPIK after one year of Korean Language Program?",
232
+ answer="Yes. Every GKS scholar (except scholars in a research program) must achieve at least Level 3 on TOPIK (Test of Proficiency in Korean) within a yearlong Korean language program to proceed to his or her degree program. In addition, certain university or department requires students to submit a valid TOPIK certificate of level 4 or higher. Scholars who applied to such department may not enter their degree program if they fail to achieve the required TOPIK certificate during a yearlong Korean language program.",
233
+ file_path="question_35.txt",
234
+ )
235
+
236
+ write_file(
237
+ question="If I become a GKS scholar, will I be assigned to a Korean language institution at a different region of my degree university?",
238
+ answer="No. From 2023, all GKS scholars will take their Korean language program at the same university where they will conduct their degree program. Exception: KAIST, UNIST, GIST, KDI School of Public Policy and Management, POSTECH will designate another university for a Korean language program. During the language program, scholars are required to live on-campus. In general, scholars are assigned to a dormitory with roommate(s). Each institution has different facilities. If an independent kitchen or a bathroom is mandatory for religious reasons, etc., please check with the university of your interest.",
239
+ file_path="question_36.txt",
240
+ )
241
+
242
+ write_file(
243
+ question="The degree program I applied to is taught in English only. May I be exempt from the Korean Language Program?",
244
+ answer="A yearlong Korean language program is an important part of the GKS program. All GKS scholars must take a Korean language program regardless of the curriculum of the degree program. However, if you have already attained advanced level (Level 5 or 6) on TOPIK when applying for the program, you must submit your valid TOPIK certificate to be exempt from Korean language program. You will directly start your degree program from September 2023. Applicants who attained TOPIK level 5 or 6 after the initial application deadline must submit the valid TOPIK certificate to NIIED by June 14, 2023. (*Acceptable TOPIK certificates: The 74 st ~ 86 th score). If you attain TOPIK level 5 or 6 during the first 6 months of Korean language program, you will be exempt from the remaining 6-month language program, and you must start your degree program in the following semester (March, 2024).",
245
+ file_path="question_37.txt",
246
+ )
247
+
248
+ write_file(
249
+ question="May I change my final university choice during my Korean language program or during a degree program?",
250
+ answer="No, you cannot. Changing the university or transferring to another university is NOT PERMITTED under any circumstances.",
251
+ file_path="question_38.txt",
252
+ )
253
+
254
+ write_file(
255
+ question="When can I apply for Korean Government Scholarship Program?",
256
+ answer="For undergraduate program, the announcement will be posted on the Korean Embassy website around August; and for graduate program, the announcement will be made around February.",
257
+ file_path="question_39.txt",
258
+ )
259
+
260
+ write_file(
261
+ question="Are the courses in Korean university conducted in Korean or English?",
262
+ answer="Nowadays English courses are offered by many universities in Korea. You need to check carefully before you select the universities by visiting the English website of the university you are interested in.",
263
+ file_path="question_40.txt",
264
+ )
265
+
266
+ write_file(
267
+ question=" I cannot speak Korean at all; can I still apply for this program?",
268
+ answer="Yes, you can. Scholarship grantees are required to take a preliminary Korean language course at the institution designated by NIIED for 1 year. However, the grantees with level 5 or higher in TOPIK (Test of Proficiency in Korean) can be exempted from the preliminary Korean language course.",
269
+ file_path="question_41.txt",
270
+ )
271
+
272
+
273
+ def generate_answer(question):
274
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
275
+ model_name_or_path = "TheBloke/Nous-Hermes-13B-GPTQ"
276
+ #model_basename_q = "nous-hermes-13b-GPTQ-4bit-128g.no-act.order"
277
+
278
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
279
+ model = AutoGPTQForCausalLM.from_quantized(
280
+ model_name_or_path,
281
+ use_safetensors=True,
282
+ trust_remote_code=True,
283
+ device=device
284
+ )
285
+
286
+ generation_config = GenerationConfig.from_pretrained(model_name_or_path)
287
+
288
+ question = (
289
+ "What Programming language should I learn as a beginner?"
290
+ )
291
+
292
+ prompt = f"""
293
+ ### instructions: {question}
294
+ ### Response:
295
+ """.strip()
296
+
297
+ # print(prompt)
298
+
299
+ # Commented out IPython magic to ensure Python compatibility.
300
+ # %%time
301
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
302
+
303
+ with torch.inference_mode():
304
+ output = model.generate(inputs = input_ids, temperature=0.7, max_new_tokens=512)
305
+
306
+
307
+ # print(tokenizer.decode(output[0]))
308
+
309
+ generation_config
310
+
311
+ streamer = TextStreamer(
312
+ tokenizer, skip_prompt=True, skip_special_tokens=True, use_multiprocessing=False
313
+ )
314
+
315
+ pipe = pipeline(
316
+ "text-generation",
317
+ model=model,
318
+ tokenizer=tokenizer,
319
+ max_length=2048,
320
+ temperature=0,
321
+ top_p=0.95,
322
+ repetition_penalty=1.15,
323
+ generation_config=generation_config,
324
+ streamer=streamer,
325
+ batch_size=1
326
+ )
327
+
328
+ llm = HuggingFacePipeline(pipeline=pipe)
329
+ embeddings = HuggingFaceEmbeddings(
330
+ model_name="embaas/sentence-transformers-multilingual-e5-base",
331
+ model_kwargs={"device": device},
332
+ )
333
+
334
+ loader = DirectoryLoader("./global-korea-scholarship/", glob="**/*txt")
335
+ documents = loader.load()
336
+ len(documents)
337
+
338
+ text_splitter = CharacterTextSplitter(chunk_size = 512, chunk_overlap=0)
339
+ texts = text_splitter.split_documents(documents)
340
+
341
+ # print(texts[0])
342
+ # print(texts[2])
343
+ # print(texts[4])
344
+
345
+ db = Chroma.from_documents(texts, embeddings)
346
+ template = """
347
+ ### Instructions: You are a scholarship support agent that is talking to a prospective scholarship applicant. Use only the chat history and the following information
348
+ {context}
349
+ to answer in a helpful manner to the question. if you don't know the answer - say that you don't know.
350
+ Keep your replies concise, informative and compassionate
351
+ {chat_history}
352
+ ### Input: {question}
353
+ ### Response:
354
+ """.strip()
355
+
356
+ prompt = PromptTemplate(
357
+ input_variables=["context", "question", "chat_history"], template=template
358
+ )
359
+ memory = ConversationBufferMemory(
360
+ memory_key = "chat_history",
361
+ human_prefix = "### Input",
362
+ ai_prefix = "### Response",
363
+ input_key = "question",
364
+ output_key = "output_text",
365
+ return_messages=False
366
+ )
367
+
368
+ chain = load_qa_chain(
369
+ llm, chain_type="stuff", prompt=prompt, memory=memory, verbose=True
370
+ )
371
+
372
+ question = "when is the result of GKS is announced?"
373
+ docs = db.similarity_search(question)
374
+ answer = chain.run({"input_documents":docs, "question":question})
375
+ return answer.strip()
376
+
377
+ gr.ChatInterface(generate_answer,
378
+ title="Nous-Hermes-GKS-chatbot",
379
+ description="Ask Nous-Hermes any question about GKS",
380
+ examples=['How to cook a fish?', 'Who is the president of US now?']
381
+ ).launch()