alpcansoydas commited on
Commit
a08048c
1 Parent(s): 2014812

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -40
app.py CHANGED
@@ -10,20 +10,20 @@ llm = HuggingFaceEndpoint(
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
 
17
  template_classify = '''
18
- You are a topic detector bot. Your task is to determine the main topic of given text phrase.
 
 
19
 
20
- Answer general main topic not specific words.
21
- Your answer does not contain specific information from given text.
22
- Answer just one general main topic. Do not answer two or more topic.
23
- Answer shortly with two or three word phrase. Do not answer with long sentence.
24
- If you do not know the topic just answer as General.
25
 
26
- What is the main topic of given text?:
27
 
28
  <text>
29
  {TEXT}
@@ -32,47 +32,26 @@ What is the main topic of given text?:
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
- """
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>
42
- {RESPONSE}
43
- </text>
44
-
45
- Your final response MUST contain only the response, no other text.
46
- Example:
47
- {{"Answer":["General"]}}
48
- '''
49
- """
50
-
51
  json_output_parser = JsonOutputParser()
52
 
53
  # Define the classify_text function
54
- def classify_text(text):
55
  global llm
56
 
57
  start = time.time()
58
- lang = detect(text)
59
-
60
- language_map = {"tr": "turkish",
61
- "en": "english",
62
- "ar": "arabic",
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,
73
- input_variables=["LANG", "TEXT"]
74
  )
75
- formatted_prompt = prompt_classify.format(TEXT=text, LANG=lang)
 
 
 
 
76
  classify = llm.invoke(formatted_prompt)
77
 
78
  '''
@@ -97,12 +76,15 @@ def gradio_app(text):
97
 
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
 
107
  iface.launch()
108
 
 
10
  repo_id="mistralai/Mistral-7B-Instruct-v0.3",
11
  task="text-generation",
12
  max_new_tokens=128,
13
+ temperature=0.5,
14
  do_sample=False,
15
  )
16
 
17
  template_classify = '''
18
+ You are an irrelevant content detector bot.
19
+ In social media, there are lots of bot accounts and they produce irrelevant contents on company hashtags.
20
+ You will detect it as Relevant or Irrelevant.
21
 
22
+ Company name: {COMPANY_NAME}
23
+ Company sector: {COMPANY_SECTOR}
24
+ About Company: {ABOUT_COMPANY}
 
 
25
 
26
+ Detect following text as RELEVANT OR IRRELEVANT:
27
 
28
  <text>
29
  {TEXT}
 
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":["RELEVANT"]}}
36
  '''
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  json_output_parser = JsonOutputParser()
39
 
40
  # Define the classify_text function
41
+ def classify_text(text, company_name_input, company_sector_input, about_company_input):
42
  global llm
43
 
44
  start = time.time()
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  prompt_classify = PromptTemplate(
47
  template=template_classify,
48
+ input_variables=["TEXT", "COMPANY_NAME", "COMPANY_SECTOR", "ABOUT_COMPANY"]
49
  )
50
+ formatted_prompt = prompt_classify.format(TEXT=text,
51
+ COMPANY_NAME=company_name_input
52
+ COMPANY_SECTOR=company_sector_input,
53
+ ABOUT_COMPANY=about_company_input
54
+ )
55
  classify = llm.invoke(formatted_prompt)
56
 
57
  '''
 
76
 
77
  def create_gradio_interface():
78
  with gr.Blocks() as iface:
79
+ company_name_input = gr.Textbox(label="Enter Company Name")
80
+ company_sector_input = gr.Textbox(label="Enter Company Sector")
81
+ about_company_input = gr.Textbox(label="Enter Information About Company")
82
  text_input = gr.Textbox(label="Text")
83
+ output_text = gr.Textbox(label="Result")
84
  time_taken = gr.Textbox(label="Time Taken (seconds)")
85
+ submit_btn = gr.Button("Detect")
86
 
87
+ submit_btn.click(fn=classify_text, inputs=[company_name_input, company_sector_input, about_company_input, text_input], outputs=[output_text, time_taken])
88
 
89
  iface.launch()
90