SinhNguyen commited on
Commit
3227970
·
1 Parent(s): e7f3990

fix bugs save caches

Browse files
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import gradio as gr
3
+ import os
4
+ import asyncio
5
+ from transformers import pipeline
6
+ import time
7
+
8
+
9
+ class TaskClassifier:
10
+
11
+ def __init__(self):
12
+ self.classifier = pipeline("zero-shot-classification",
13
+ model="facebook/bart-large-mnli")
14
+
15
+ def __call__(self, client_input: str, task_types: str):
16
+ """Classify tasks for LLM-based gent"""
17
+ candidate_labels = [label.strip() for label in task_types.split(",")]
18
+ time_execution = time.time()
19
+ output = self.classifier(str(client_input), candidate_labels, multi_label=False)
20
+ # output = classifier(input, candidate_labels, multi_label=False)
21
+ time_execution = round(time.time() - time_execution, 2)
22
+ # return {"task_type": output['labels'][0], "confidence": round(output['scores'][0],2), "inference_time": time_execution}
23
+ return f"Task Type : {output['labels'][0]}\nScore : {round(output['scores'][0],2)}\nInference Time : {time_execution}"
24
+
25
+
26
+
27
+
28
+ def load_classifier(client_input, task_types):
29
+ global classifier
30
+ return classifier(client_input, task_types)
31
+
32
+
33
+ def question_answer(client_input, task_types):
34
+ if client_input.strip()=='':
35
+ return '''[ERROR]: Please enter client input (e.g., 'Find the top products for a given category').'''
36
+ if task_types.strip() == '':
37
+ return '''[ERROR]: Please enter list of task type of LLM-based agents (e.g., 'Greeting, Information retrieval, Sentiment analysis, Text generation, Code generation, Q&A, Summarize'): '''
38
+ return load_classifier(client_input, task_types)
39
+
40
+
41
+ classifier = TaskClassifier()
42
+
43
+ title = 'Task Clarity for LLM-based Agents'
44
+ description = """ Task Clarity for LLM-based Agents is a powerful tool that assists developers in crafting precise task instructions, identifies task types (e.g., Q&A, Text generation) for your LLM-based Agents."""
45
+
46
+
47
+ with gr.Blocks() as demo:
48
+
49
+ gr.Markdown(f'<center><h1>{title}</h1></center>')
50
+ gr.Markdown(description)
51
+
52
+ with gr.Row():
53
+
54
+ with gr.Group():
55
+ gr.Markdown(f'<p style="text-align:center">Report about the model: <a href="https://sinh-nguyen.notion.site/Report-Solving-Task-Clarity-for-LLM-based-Agents-4b49b5229a3f423984743b11f3c2bec8">here</a></p>')
56
+ client_input=gr.Textbox(label='''Please enter client's input (e.g., 'Hello?'): ''')
57
+ task_types = gr.Textbox(label='''Please enter list of task type of LLM-based agents (e.g., 'Greeting, Information retrieval, Sentiment analysis, Text generation, Code generation, Q&A, Summarization'): ''')
58
+ btn = gr.Button(value='Submit')
59
+ btn.style(full_width=True)
60
+ #openai.api_key = os.getenv('Your_Key_Here')
61
+ with gr.Group():
62
+ answer = gr.Textbox(label='The answer to your question is :')
63
+
64
+ btn.click(question_answer, inputs=[client_input, task_types], outputs=[answer])
65
+
66
+ demo.launch(share=True)
67
+ # demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ huggingface_hub
2
+ git+https://github.com/huggingface/transformers
3
+ accelerate
4
+ peft
5
+ bitsandbytes
6
+ trl
7
+ py7zr
8
+ gradio==3.42.0