Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,8 @@ import time
|
|
| 9 |
llm = HuggingFaceEndpoint(
|
| 10 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 11 |
task="text-generation",
|
| 12 |
-
max_new_tokens=
|
| 13 |
-
temperature=0.
|
| 14 |
do_sample=False,
|
| 15 |
)
|
| 16 |
|
|
@@ -28,6 +28,11 @@ What is the main topic of given text?:
|
|
| 28 |
<text>
|
| 29 |
{TEXT}
|
| 30 |
</text>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
'''
|
| 32 |
|
| 33 |
template_json = '''
|
|
@@ -65,15 +70,18 @@ def classify_text(text):
|
|
| 65 |
formatted_prompt = prompt_classify.format(TEXT=text, LANG=lang)
|
| 66 |
classify = llm.invoke(formatted_prompt)
|
| 67 |
|
|
|
|
| 68 |
prompt_json = PromptTemplate(
|
| 69 |
template=template_json,
|
| 70 |
input_variables=["RESPONSE"]
|
| 71 |
)
|
|
|
|
| 72 |
|
| 73 |
-
formatted_prompt = template_json.format(RESPONSE=classify)
|
| 74 |
-
response = llm.invoke(formatted_prompt)
|
| 75 |
|
| 76 |
-
|
|
|
|
| 77 |
end = time.time()
|
| 78 |
duration = end - start
|
| 79 |
return parsed_output, duration #['Answer']
|
|
|
|
| 9 |
llm = HuggingFaceEndpoint(
|
| 10 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 11 |
task="text-generation",
|
| 12 |
+
max_new_tokens=128,
|
| 13 |
+
temperature=0.3,
|
| 14 |
do_sample=False,
|
| 15 |
)
|
| 16 |
|
|
|
|
| 28 |
<text>
|
| 29 |
{TEXT}
|
| 30 |
</text>
|
| 31 |
+
|
| 32 |
+
convert it to json format using 'Answer' as key and return it.
|
| 33 |
+
Your final response MUST contain only the response, no other text.
|
| 34 |
+
Example:
|
| 35 |
+
{{"Answer":["General"]}}
|
| 36 |
'''
|
| 37 |
|
| 38 |
template_json = '''
|
|
|
|
| 70 |
formatted_prompt = prompt_classify.format(TEXT=text, LANG=lang)
|
| 71 |
classify = llm.invoke(formatted_prompt)
|
| 72 |
|
| 73 |
+
'''
|
| 74 |
prompt_json = PromptTemplate(
|
| 75 |
template=template_json,
|
| 76 |
input_variables=["RESPONSE"]
|
| 77 |
)
|
| 78 |
+
'''
|
| 79 |
|
| 80 |
+
#formatted_prompt = template_json.format(RESPONSE=classify)
|
| 81 |
+
#response = llm.invoke(formatted_prompt)
|
| 82 |
|
| 83 |
+
|
| 84 |
+
parsed_output = json_output_parser.parse(classify)
|
| 85 |
end = time.time()
|
| 86 |
duration = end - start
|
| 87 |
return parsed_output, duration #['Answer']
|