Spaces:
Sleeping
Sleeping
| # import gradio as gr | |
| # from huggingface_hub import InferenceClient | |
| # """ | |
| # For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference | |
| # """ | |
| # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") | |
| # def respond( | |
| # message, | |
| # history: list[tuple[str, str]], | |
| # system_message, | |
| # max_tokens, | |
| # temperature, | |
| # top_p, | |
| # ): | |
| # messages = [{"role": "system", "content": system_message}] | |
| # for val in history: | |
| # if val[0]: | |
| # messages.append({"role": "user", "content": val[0]}) | |
| # if val[1]: | |
| # messages.append({"role": "assistant", "content": val[1]}) | |
| # messages.append({"role": "user", "content": message}) | |
| # response = "" | |
| # for message in client.chat_completion( | |
| # messages, | |
| # max_tokens=max_tokens, | |
| # stream=True, | |
| # temperature=temperature, | |
| # top_p=top_p, | |
| # ): | |
| # token = message.choices[0].delta.content | |
| # response += token | |
| # yield response | |
| # """ | |
| # For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface | |
| # """ | |
| # demo = gr.ChatInterface( | |
| # respond, | |
| # additional_inputs=[ | |
| # gr.Textbox(value="You are a friendly Chatbot.", label="System message"), | |
| # gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), | |
| # gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), | |
| # gr.Slider( | |
| # minimum=0.1, | |
| # maximum=1.0, | |
| # value=0.95, | |
| # step=0.05, | |
| # label="Top-p (nucleus sampling)", | |
| # ), | |
| # ], | |
| # ) | |
| # if __name__ == "__main__": | |
| # demo.launch() | |
| import gradio as gr | |
| from PIL import Image | |
| # —— 在这里根据你自己的 Agent 框架实现这个函数 —— | |
| def run_agent_on_image(original_img: Image.Image, prompt: str, agent_name: str) -> Image.Image: | |
| """ | |
| 调用指定 agent(模型/工具)处理图片并返回结果 | |
| original_img: PIL Image | |
| prompt: 用户输入的描述 | |
| agent_name: 在下拉框里选的模型名称 | |
| """ | |
| # 示例逻辑(请替换为真正的 agent 调用) | |
| # if agent_name == "Model A": | |
| # return model_a.process(original_img, prompt) | |
| # elif agent_name == "Model B": | |
| # return model_b.process(original_img, prompt) | |
| return original_img # TODO: 删除这行 | |
| # 可选:把可用的 agent 列表写成一个文件或者直接在这里列出 | |
| MODEL_CHOICES = ["Model A", "Model B", "Model C"] | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## CV Agent Arena 🎨🤖\nUpload the image you want to process, provide your requirements, select two Agents, and click 'Run Agents' to compare the results!") | |
| with gr.Row(): | |
| with gr.Column(): | |
| original = gr.Image(type="pil", label="Upload Original Image") | |
| prompt = gr.Textbox(lines=2, placeholder="e.g. ‘Make it look like a sunny day’", label="Prompt") | |
| with gr.Column(): | |
| agent1 = gr.Dropdown(choices=MODEL_CHOICES, label="Select Agent 1") | |
| agent2 = gr.Dropdown(choices=MODEL_CHOICES, label="Select Agent 2") | |
| # 处理按钮 | |
| run_btn = gr.Button("Run Agents") | |
| with gr.Row(): | |
| # 左侧输出:Agent1 结果 | |
| with gr.Column(): | |
| out1 = gr.Image(type="pil", label="Agent 1 Output") | |
| # 右侧输出:Agent2 结果 | |
| with gr.Column(): | |
| out2 = gr.Image(type="pil", label="Agent 2 Output") | |
| # 按钮绑定 | |
| run_btn.click( | |
| fn=lambda img, p, a1, a2: (run_agent_on_image(img, p, a1), run_agent_on_image(img, p, a2)), | |
| inputs=[original, prompt, agent1, agent2], | |
| outputs=[out1, out2], | |
| ) | |
| if __name__ == "__main__": | |
| demo.queue() | |
| demo.launch() | |