|
import os |
|
import json |
|
import arxiv |
|
|
|
|
|
import requests |
|
from typing import Tuple |
|
from bs4 import BeautifulSoup |
|
from huggingface_hub import HfApi |
|
from pypdf import PdfReader |
|
from models import HfApiModel |
|
from smolagents import CodeAgent, tool, GradioUI |
|
|
|
from smolagents.monitoring import LogLevel |
|
|
|
|
|
@tool |
|
def process_file_transfer_result(job_id: str) -> Tuple: |
|
""" |
|
This function processes the logs sent by the server. |
|
Args: |
|
job_id: The job identifier of the initated file transfer |
|
Returns: |
|
True if the transfer suceeded and the corresponding message if an error occured. |
|
""" |
|
|
|
return True, '' |
|
|
|
|
|
@tool |
|
def request_file_transfer(file_path: str, server: str) -> str: |
|
""" |
|
This function sends a request for a file transfer initiation. |
|
Args: |
|
file_path: The path to the source file. |
|
server: identifier of the file transfer server |
|
Returns: |
|
The job identifier of the initated file transfer |
|
|
|
""" |
|
|
|
return 'trans001' |
|
|
|
|
|
@tool |
|
def encrypt_file(file_path: str) -> bool: |
|
""" |
|
This function encrypts the source file. |
|
Args: |
|
file_path: The path to the source file. |
|
Returns: |
|
True if encryption went well |
|
""" |
|
print(f'File {file_path} encrypted') |
|
|
|
return True |
|
|
|
@tool |
|
def validate_file(file_path: str) -> str: |
|
""" |
|
This function validates that the source file exists. |
|
Args: |
|
file_path: The path to the source file. |
|
Returns: |
|
A boolean value indicateing the existance of a file. |
|
""" |
|
|
|
return True |
|
|
|
model_id = "Qwen/Qwen2.5-Coder-32B-Instruct" |
|
hf_token = os.environ["HF_TOKEN"] |
|
|
|
|
|
model = HfApiModel(model_id=model_id, token=hf_token) |
|
agent = CodeAgent(tools=[process_file_transfer_result, |
|
validate_file, |
|
encrypt_file, |
|
request_file_transfer, |
|
], |
|
verbosity_level=LogLevel.DEBUG, |
|
model=model, |
|
add_base_tools=True) |
|
|
|
agent.visualize() |
|
|
|
|
|
|
|
|
|
|
|
|
|
GradioUI(agent).launch() |