alpcansoydas commited on
Commit
233c0df
1 Parent(s): ac51a4b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
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 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,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 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
 
 
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