DenverJones commited on
Commit
f3fdf8e
·
verified ·
1 Parent(s): 81e4fe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -32
app.py CHANGED
@@ -1,52 +1,36 @@
1
- from smolagents import CodeAgent, HfApiModel, tool
2
- import yaml
3
- from Gradio_UI import GradioUI
4
  import gradio as gr
 
 
5
 
6
- # Define a tool to generate motivational quotes
7
  @tool
8
  def get_motivational_quote() -> str:
9
- """Returns a motivational quote to inspire the user."""
10
  quotes = [
11
  "Believe you can and you're halfway there.",
12
  "Your limitation—it's only your imagination.",
13
- "Push yourself, because no one else is going to do it for you.",
14
- "Great things never come from comfort zones.",
15
- "Dream it. Wish it. Do it."
16
  ]
17
- import random
18
  return random.choice(quotes)
19
 
20
- # Model setup
21
- model = HfApiModel(
22
- max_tokens=2096,
23
- temperature=0.5,
24
- model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud')
25
 
26
- # Load prompt templates
27
- with open("prompts.yaml", 'r') as stream:
28
- prompt_templates = yaml.safe_load(stream)
29
 
30
- # Create the agent
31
- agent = CodeAgent(
32
- model=model,
33
- tools=[get_motivational_quote], # Only the necessary tool
34
- max_steps=3,
35
- verbosity_level=1,
36
- name="MotivationAgent",
37
- description="An agent that provides motivational quotes to inspire users.",
38
- prompt_templates=prompt_templates,
39
- )
40
 
41
- # Launch the Gradio UI with custom interaction
42
  def respond(user_input):
43
- quote = get_motivational_quote() # Get a quote immediately
44
- return quote # Return the quote to display in the output
45
 
46
  with gr.Blocks() as demo:
47
  text_input = gr.Textbox()
48
  text_output = gr.Textbox()
49
- text_input.change(respond, inputs=text_input, outputs=text_output) # Trigger on input change
50
 
51
  demo.launch()
52
-
 
 
 
 
1
  import gradio as gr
2
+ from smolagents import CodeAgent, HfApiModel, tool
3
+ import random
4
 
5
+ # Define a tool to get motivational quotes (using a simple list for this example)
6
  @tool
7
  def get_motivational_quote() -> str:
8
+ """Returns a motivational quote."""
9
  quotes = [
10
  "Believe you can and you're halfway there.",
11
  "Your limitation—it's only your imagination.",
12
+ "The only way to do great work is to love what you do.",
13
+ "Strive not to be a success, but rather to be of value.",
14
+ "The future belongs to those who believe in the beauty of their dreams."
15
  ]
 
16
  return random.choice(quotes)
17
 
18
+ # Initialize the agent (using a dummy model for this simplified example)
19
+ class DummyModel: # Replace with a real Hugging Face model
20
+ def generate(self, prompt, **kwargs):
21
+ return {"generated_text": ""} # Return empty string for simplicity
 
22
 
23
+ dummy_model = DummyModel()
24
+ agent = CodeAgent(tools=[get_motivational_quote], model=dummy_model)
 
25
 
 
 
 
 
 
 
 
 
 
 
26
 
 
27
  def respond(user_input):
28
+ quote = agent.run(user_input) # Run the agent with the user input
29
+ return quote["final_answer"] # Extract the quote from the agent's response
30
 
31
  with gr.Blocks() as demo:
32
  text_input = gr.Textbox()
33
  text_output = gr.Textbox()
34
+ text_input.change(respond, inputs=text_input, outputs=text_output)
35
 
36
  demo.launch()