Chan-Y commited on
Commit
bf3ac4c
1 Parent(s): 9be919d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -20
app.py CHANGED
@@ -7,6 +7,7 @@ from langchain.prompts import PromptTemplate
7
  from pathlib import Path
8
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
9
  from langchain_core.output_parsers import JsonOutputParser
 
10
 
11
  llm = HuggingFaceEndpoint(
12
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
@@ -34,26 +35,7 @@ def summarize(file, n_words):
34
  with open(file_path, 'r', encoding='utf-8') as f:
35
  text = f.read()
36
 
37
- template_detect = '''
38
- Please carefully read the following document:
39
-
40
- <document>
41
- {TEXT}
42
- </document>
43
-
44
- identify the MOST used language in the document, return detected language in json format with key "language" and value is the detected language
45
- '''
46
-
47
- prompt_detect = PromptTemplate(
48
- template=template_detect,
49
- input_variables=['TEXT']
50
- )
51
-
52
- language_detect = prompt_detect | llm | JsonOutputParser()
53
- formatted_prompt = prompt_detect.format(TEXT=text)
54
- language = language_detect.invoke(formatted_prompt)
55
-
56
- lang = language["language"]
57
  template_translate = '''
58
  Please carefully read the following document:
59
  <document>
 
7
  from pathlib import Path
8
  from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
9
  from langchain_core.output_parsers import JsonOutputParser
10
+ from langdetect import detect
11
 
12
  llm = HuggingFaceEndpoint(
13
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
 
35
  with open(file_path, 'r', encoding='utf-8') as f:
36
  text = f.read()
37
 
38
+ lang = detect(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  template_translate = '''
40
  Please carefully read the following document:
41
  <document>