Spaces:
Sleeping
Sleeping
alpcansoydas
commited on
Commit
•
ac51a4b
1
Parent(s):
594bc5d
Upload app.py
Browse files
app.py
CHANGED
@@ -15,30 +15,25 @@ llm = HuggingFaceEndpoint(
|
|
15 |
)
|
16 |
llm_engine_hf = ChatHuggingFace(llm=llm)
|
17 |
|
|
|
18 |
template_classify = '''
|
19 |
-
Please
|
|
|
20 |
|
21 |
<text>
|
22 |
{TEXT}
|
23 |
</text>
|
24 |
-
|
25 |
-
After reading it, I want you to classify it in three groups: Positive, Negative, or Neutral.
|
26 |
-
Your final response MUST contain only the response, no other text.
|
27 |
-
Example:
|
28 |
-
Positive
|
29 |
-
Negative
|
30 |
-
Neutral
|
31 |
'''
|
32 |
|
33 |
template_json = '''
|
34 |
-
Your task is to read the following
|
|
|
35 |
<text>
|
36 |
{RESPONSE}
|
37 |
</text>
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
{{"Answer":"Positive"}}
|
42 |
'''
|
43 |
json_output_parser = JsonOutputParser()
|
44 |
|
@@ -67,7 +62,7 @@ def classify_text(text):
|
|
67 |
parsed_output = json_output_parser.parse(response)
|
68 |
end = time.time()
|
69 |
duration = end - start
|
70 |
-
return parsed_output, duration
|
71 |
|
72 |
# Create the Gradio interface
|
73 |
def gradio_app(text):
|
@@ -77,11 +72,11 @@ def gradio_app(text):
|
|
77 |
def create_gradio_interface():
|
78 |
with gr.Blocks() as iface:
|
79 |
text_input = gr.Textbox(label="Text to Classify")
|
80 |
-
output_text = gr.Textbox(label="
|
81 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
82 |
-
submit_btn = gr.Button("
|
83 |
|
84 |
-
submit_btn.click(fn=
|
85 |
|
86 |
iface.launch()
|
87 |
|
|
|
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 and extract the main topics discussed in it.
|
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 extracted topics and convert them into JSON format using 'Topics' as the key.
|
30 |
+
|
31 |
<text>
|
32 |
{RESPONSE}
|
33 |
</text>
|
34 |
|
35 |
+
The final response should be in this format:
|
36 |
+
{{"Topics": ["Topic1", "Topic2", ...]}}
|
|
|
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
|
66 |
|
67 |
# Create the Gradio interface
|
68 |
def gradio_app(text):
|
|
|
72 |
def create_gradio_interface():
|
73 |
with gr.Blocks() as iface:
|
74 |
text_input = gr.Textbox(label="Text to Classify")
|
75 |
+
output_text = gr.Textbox(label="Extracted Topics")
|
76 |
time_taken = gr.Textbox(label="Time Taken (seconds)")
|
77 |
+
submit_btn = gr.Button("Extract Topics")
|
78 |
|
79 |
+
submit_btn.click(fn=gradio_app, inputs=text_input, outputs=[output_text, time_taken])
|
80 |
|
81 |
iface.launch()
|
82 |
|