File size: 1,534 Bytes
d10bbd6
7bbce45
d10bbd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7bbce45
 
d10bbd6
7bbce45
d10bbd6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Import necessary libraries
import gradio as gr
from smolagents import Agent  # Replace with your actual import if different

# Step 1: Set up your smolagents agent
def create_agent():
    """
    Initialize and return the agent.
    Adjust parameters like model type or configuration as needed.
    """
    # For example, we initialize an Agent with a sample model
    agent = Agent(model=HfApiModel(model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/'))  # Change arguments as per your agent configuration
    return agent

# Create the agent instance once so that it persists across user interactions
agent = create_agent()

# Step 2: Define a function that uses the agent to process user input
def process_input(user_input):
    """
    This function receives user input from the Gradio interface,
    processes it with the smolagents agent, and returns the agent's response.
    """
    # Use your agent's method to generate a response; here we assume a 'run' method exists.
    response = agent.run(user_input)
    return response

# Step 3: Build the Gradio interface
iface = gr.Interface(
    fn=process_input,  # This is the function Gradio will call when a user submits input.
    inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
    outputs="text",
    title="Smolagents Agent via Gradio",
    description="This interface integrates a smolagents-based agent with Gradio to process text inputs."
)

# Step 4: Launch the Gradio app
if __name__ == "__main__":
    iface.launch()