Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 7 |
@tool
|
| 8 |
def get_motivational_quote() -> str:
|
| 9 |
-
"""Returns a motivational quote
|
| 10 |
quotes = [
|
| 11 |
"Believe you can and you're halfway there.",
|
| 12 |
"Your limitation—it's only your imagination.",
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
]
|
| 17 |
-
import random
|
| 18 |
return random.choice(quotes)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud')
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 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 =
|
| 44 |
-
return quote #
|
| 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)
|
| 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()
|
|
|