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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from smolagents import CodeAgent, HfApiModel, tool
2
  import yaml
3
  from Gradio_UI import GradioUI
 
4
 
5
  # Define a tool to generate motivational quotes
6
  @tool
@@ -20,13 +21,12 @@ def get_motivational_quote() -> str:
20
  model = HfApiModel(
21
  max_tokens=2096,
22
  temperature=0.5,
23
- model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud'
24
- )
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,
@@ -35,10 +35,18 @@ agent = CodeAgent(
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
42
- GradioUI(agent).launch()
 
 
43
 
 
44
 
 
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
 
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,
 
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