Spaces:
Paused
Paused
Numerous fixes
Browse files4 unmodified lines567891011121314151621 unmodified lines38394041424362 unmodified lines10610710810911011111211311411560 unmodified lines1761771781791801811821831841851861871881891901911921 unmodified line19419519619719819920020114 unmodified lines21621721821922022122222339 unmodified lines2632642652662672682692704 unmodified linesfrom concurrent.futures import ThreadPoolExecutor, as_completedfrom datetime import datetimefrom pathlib import Pathfrom typing import Listimport datasetsimport pandas as pdfrom dotenv import load_dotenvfrom huggingface_hub import loginfrom scripts.reformulator import prepare_responsefrom scripts.run_agents import (get_single_file_description,21 unmodified linesModel,ToolCallingAgent,)AUTHORIZED_IMPORTS = [62 unmodified linesos.makedirs(f"./{BROWSER_CONFIG['downloads_folder']}", exist_ok=True)model = HfApiModel("Qwen/Qwen2.5-32B-Instruct",custom_role_conversions=custom_role_conversions,)text_limit = 2000060 unmodified lines# final_result = agent.run(augmented_question)import gradio as grfrom smolagents.gradio_ui import stream_to_gradioclass GradioUI:"""A one-line interface to launch your agent in Gradio"""def __init__(self, agent: MultiStepAgent, file_upload_folder: str | None = None):if not _is_package_available("gradio"):raise ModuleNotFoundError("Please install 'gradio' extra to use the GradioUI: `pip install 'smolagents[gradio]'`")self.agent = agentself.file_upload_folder = file_upload_folderif self.file_upload_folder is not None:1 unmodified lineos.mkdir(file_upload_folder)def interact_with_agent(self, prompt, messages):import gradio as grmessages.append(gr.ChatMessage(role="user", content=prompt))yield messagesfor msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):14 unmodified lines"""Handle file uploads, default allowed types are .pdf, .docx, and .txt"""import gradio as grif file is None:return gr.Textbox("No file uploaded", visible=True), file_uploads_log39 unmodified lines)def launch(self, **kwargs):import gradio as grwith gr.Blocks(fill_height=True) as demo:stored_messages = gr.State([])file_uploads_log = gr.State([])4 unmodified lines5678910111213141516171821 unmodified lines4041424344454662 unmodified lines10911011111211311411511611711860 unmodified lines1791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232241 unmodified line22622722822923023114 unmodified lines24624724824925025139 unmodified lines2912922932942952964 unmodified linesfrom concurrent.futures import ThreadPoolExecutor, as_completedfrom datetime import datetimefrom pathlib import Pathfrom typing import List, Optionalimport datasetsimport pandas as pdfrom dotenv import load_dotenvfrom huggingface_hub import loginimport gradio as grfrom scripts.reformulator import prepare_responsefrom scripts.run_agents import (get_single_file_description,21 unmodified linesModel,ToolCallingAgent,)from smolagents.gradio_ui import pull_messages_from_step, handle_agent_output_typesAUTHORIZED_IMPORTS = [62 unmodified linesos.makedirs(f"./{BROWSER_CONFIG['downloads_folder']}", exist_ok=True)model = LiteLLMModel("gpt-4o",custom_role_conversions=custom_role_conversions,api_key=os.getenv("OPENAI_API_KEY"))text_limit = 2000060 unmodified lines# final_result = agent.run(augmented_question)def stream_to_gradio(agent,task: str,reset_agent_memory: bool = False,additional_args: Optional[dict] = None,):"""Runs an agent with the given task and streams the messages from the agent as gradio ChatMessages."""for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):for message in pull_messages_from_step(step_log,):yield messagefinal_answer = step_log # Last log is the run's final_answerfinal_answer = handle_agent_output_types(final_answer)if isinstance(final_answer, AgentText):yield gr.ChatMessage(role="assistant",content=f"**Final answer:**\n{final_answer.to_string()}\n",)elif isinstance(final_answer, AgentImage):yield gr.ChatMessage(role="assistant",content={"path": final_answer.to_string(), "mime_type": "image/png"},)elif isinstance(final_answer, AgentAudio):yield gr.ChatMessage(role="assistant",content={"path": final_answer.to_string(), "mime_type": "audio/wav"},)else:yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")class GradioUI:"""A one-line interface to launch your agent in Gradio"""def __init__(self, agent, file_upload_folder: str | None = None):self.agent = agentself.file_upload_folder = file_upload_folderif self.file_upload_folder is not None:1 unmodified lineos.mkdir(file_upload_folder)def interact_with_agent(self, prompt, messages):messages.append(gr.ChatMessage(role="user", content=prompt))yield messagesfor msg in stream_to_gradio(self.agent, task=prompt, reset_agent_memory=False):14 unmodified lines"""Handle file uploads, default allowed types are .pdf, .docx, and .txt"""if file is None:return gr.Textbox("No file uploaded", visible=True), file_uploads_log39 unmodified lines)def launch(self, **kwargs):with gr.Blocks(fill_height=True) as demo:stored_messages = gr.State([])file_uploads_log = gr.State([])
app.py+43-17