Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ llm = HuggingFaceEndpoint(
|
|
| 10 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 11 |
task="text-generation",
|
| 12 |
max_new_tokens=128,
|
| 13 |
-
temperature=0.
|
| 14 |
do_sample=False,
|
| 15 |
)
|
| 16 |
|
|
@@ -35,6 +35,7 @@ Example:
|
|
| 35 |
{{"Answer":["General"]}}
|
| 36 |
'''
|
| 37 |
|
|
|
|
| 38 |
template_json = '''
|
| 39 |
Your task is to read the following text, convert it to json format using 'Answer' as key and return it.
|
| 40 |
<text>
|
|
@@ -45,6 +46,7 @@ Your final response MUST contain only the response, no other text.
|
|
| 45 |
Example:
|
| 46 |
{{"Answer":["General"]}}
|
| 47 |
'''
|
|
|
|
| 48 |
|
| 49 |
json_output_parser = JsonOutputParser()
|
| 50 |
|
|
@@ -61,7 +63,10 @@ def classify_text(text):
|
|
| 61 |
"es": "spanish",
|
| 62 |
"it": "italian",
|
| 63 |
}
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
prompt_classify = PromptTemplate(
|
| 67 |
template=template_classify,
|
|
@@ -80,7 +85,6 @@ def classify_text(text):
|
|
| 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
|
|
@@ -94,9 +98,9 @@ def gradio_app(text):
|
|
| 94 |
def create_gradio_interface():
|
| 95 |
with gr.Blocks() as iface:
|
| 96 |
text_input = gr.Textbox(label="Text")
|
| 97 |
-
output_text = gr.Textbox(label="Topics")
|
| 98 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
| 99 |
-
submit_btn = gr.Button("
|
| 100 |
|
| 101 |
submit_btn.click(fn=classify_text, inputs=text_input, outputs=[output_text, time_taken])
|
| 102 |
|
|
|
|
| 10 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 11 |
task="text-generation",
|
| 12 |
max_new_tokens=128,
|
| 13 |
+
temperature=0.7,
|
| 14 |
do_sample=False,
|
| 15 |
)
|
| 16 |
|
|
|
|
| 35 |
{{"Answer":["General"]}}
|
| 36 |
'''
|
| 37 |
|
| 38 |
+
"""
|
| 39 |
template_json = '''
|
| 40 |
Your task is to read the following text, convert it to json format using 'Answer' as key and return it.
|
| 41 |
<text>
|
|
|
|
| 46 |
Example:
|
| 47 |
{{"Answer":["General"]}}
|
| 48 |
'''
|
| 49 |
+
"""
|
| 50 |
|
| 51 |
json_output_parser = JsonOutputParser()
|
| 52 |
|
|
|
|
| 63 |
"es": "spanish",
|
| 64 |
"it": "italian",
|
| 65 |
}
|
| 66 |
+
try:
|
| 67 |
+
lang = language_map[lang]
|
| 68 |
+
except:
|
| 69 |
+
lang = "en"
|
| 70 |
|
| 71 |
prompt_classify = PromptTemplate(
|
| 72 |
template=template_classify,
|
|
|
|
| 85 |
#formatted_prompt = template_json.format(RESPONSE=classify)
|
| 86 |
#response = llm.invoke(formatted_prompt)
|
| 87 |
|
|
|
|
| 88 |
parsed_output = json_output_parser.parse(classify)
|
| 89 |
end = time.time()
|
| 90 |
duration = end - start
|
|
|
|
| 98 |
def create_gradio_interface():
|
| 99 |
with gr.Blocks() as iface:
|
| 100 |
text_input = gr.Textbox(label="Text")
|
| 101 |
+
output_text = gr.Textbox(label="Detected Topics")
|
| 102 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
| 103 |
+
submit_btn = gr.Button("Detect topic")
|
| 104 |
|
| 105 |
submit_btn.click(fn=classify_text, inputs=text_input, outputs=[output_text, time_taken])
|
| 106 |
|