ans123 commited on
Commit
f8140a4
·
verified ·
1 Parent(s): 3fd747d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the text-generation pipeline
5
+ pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype="auto", device_map="auto")
6
+
7
+ # Define agent roles
8
+ agents = {
9
+ "Pirate": "You are a friendly chatbot who always responds in the style of a pirate.",
10
+ "Professor": "You are a knowledgeable professor who explains concepts in detail.",
11
+ "Comedian": "You are a witty comedian who answers with humor and jokes.",
12
+ "Motivator": "You are a motivational speaker who provides inspiring and uplifting responses.",
13
+ }
14
+
15
+ def multi_agent_system(agent, user_input):
16
+ # Set the role of the selected agent
17
+ messages = [
18
+ {"role": "system", "content": agents[agent]},
19
+ {"role": "user", "content": user_input},
20
+ ]
21
+ # Format the chat template
22
+ prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
23
+ # Generate the response
24
+ outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
25
+ return outputs[0]["generated_text"]
26
+
27
+ # Gradio UI
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("# Multi-Agent Chat System")
30
+
31
+ with gr.Row():
32
+ agent_dropdown = gr.Dropdown(
33
+ choices=list(agents.keys()), label="Select an Agent", value="Pirate"
34
+ )
35
+ user_input = gr.Textbox(label="Enter your message:", placeholder="Type your query here...")
36
+
37
+ submit_button = gr.Button("Submit")
38
+ chat_output = gr.Textbox(label="Agent's Response:", interactive=False)
39
+
40
+ submit_button.click(
41
+ fn=multi_agent_system,
42
+ inputs=[agent_dropdown, user_input],
43
+ outputs=chat_output
44
+ )
45
+
46
+ # Launch the app
47
+ demo.launch()