Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -15,25 +15,25 @@ llm = HuggingFaceEndpoint(
|
|
| 15 |
)
|
| 16 |
llm_engine_hf = ChatHuggingFace(llm=llm)
|
| 17 |
|
| 18 |
-
# Update the template to extract topic information
|
| 19 |
template_classify = '''
|
| 20 |
-
Please read the following text written in {LANG} language
|
| 21 |
-
You can list more than one topic or topics sentence by sentence. List the topics clearly.
|
| 22 |
|
| 23 |
<text>
|
| 24 |
{TEXT}
|
| 25 |
</text>
|
|
|
|
|
|
|
| 26 |
'''
|
| 27 |
|
| 28 |
template_json = '''
|
| 29 |
-
Your task is to read the following
|
| 30 |
-
|
| 31 |
<text>
|
| 32 |
{RESPONSE}
|
| 33 |
</text>
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
'''
|
| 38 |
json_output_parser = JsonOutputParser()
|
| 39 |
|
|
@@ -62,7 +62,7 @@ def classify_text(text):
|
|
| 62 |
parsed_output = json_output_parser.parse(response)
|
| 63 |
end = time.time()
|
| 64 |
duration = end - start
|
| 65 |
-
return parsed_output, duration
|
| 66 |
|
| 67 |
# Create the Gradio interface
|
| 68 |
def gradio_app(text):
|
|
@@ -71,12 +71,12 @@ def gradio_app(text):
|
|
| 71 |
|
| 72 |
def create_gradio_interface():
|
| 73 |
with gr.Blocks() as iface:
|
| 74 |
-
text_input = gr.Textbox(label="Text
|
| 75 |
-
output_text = gr.Textbox(label="
|
| 76 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
| 77 |
-
submit_btn = gr.Button("
|
| 78 |
|
| 79 |
-
submit_btn.click(fn=
|
| 80 |
|
| 81 |
iface.launch()
|
| 82 |
|
|
|
|
| 15 |
)
|
| 16 |
llm_engine_hf = ChatHuggingFace(llm=llm)
|
| 17 |
|
|
|
|
| 18 |
template_classify = '''
|
| 19 |
+
Please carefully read the following text. The text is written in {LANG} language:
|
|
|
|
| 20 |
|
| 21 |
<text>
|
| 22 |
{TEXT}
|
| 23 |
</text>
|
| 24 |
+
|
| 25 |
+
After reading it, I want you to extract topic informations from text.
|
| 26 |
'''
|
| 27 |
|
| 28 |
template_json = '''
|
| 29 |
+
Your task is to read the following text, convert it to json format using 'Answer' as key and return it.
|
|
|
|
| 30 |
<text>
|
| 31 |
{RESPONSE}
|
| 32 |
</text>
|
| 33 |
|
| 34 |
+
Your final response MUST contain only the response, no other text.
|
| 35 |
+
Example:
|
| 36 |
+
{{"Answer":"Positive"}}
|
| 37 |
'''
|
| 38 |
json_output_parser = JsonOutputParser()
|
| 39 |
|
|
|
|
| 62 |
parsed_output = json_output_parser.parse(response)
|
| 63 |
end = time.time()
|
| 64 |
duration = end - start
|
| 65 |
+
return parsed_output, duration #['Answer']
|
| 66 |
|
| 67 |
# Create the Gradio interface
|
| 68 |
def gradio_app(text):
|
|
|
|
| 71 |
|
| 72 |
def create_gradio_interface():
|
| 73 |
with gr.Blocks() as iface:
|
| 74 |
+
text_input = gr.Textbox(label="Text")
|
| 75 |
+
output_text = gr.Textbox(label="Classify")
|
| 76 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
| 77 |
+
submit_btn = gr.Button("Classify")
|
| 78 |
|
| 79 |
+
submit_btn.click(fn=classify_text, inputs=text_input, outputs=[output_text, time_taken])
|
| 80 |
|
| 81 |
iface.launch()
|
| 82 |
|