Spaces:
Running
Running
File size: 1,423 Bytes
e9a7740 1876937 82a64c8 1876937 82a64c8 e9a7740 82a64c8 1876937 82a64c8 80d7b75 1876937 82a64c8 bcee032 1876937 82a64c8 1876937 40c24e4 |
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 41 42 43 44 45 46 47 48 49 50 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gradio as gr
from simple_inference import predict_location
import os
# 设置默认模型和引擎
DEFAULT_MODEL = "TheEighthDay/SeekWorld_RL_PLUS"
DEFAULT_ENGINE = "transformers"
def process_image(image, model_name, inference_engine):
# 保存上传的图片到临时文件
temp_path = "temp_image.jpg"
image.save(temp_path)
try:
# 调用预测函数
result = predict_location(
image_path=temp_path,
model_name=model_name,
inference_engine=inference_engine
)
# 删除临时文件
os.remove(temp_path)
return result
except Exception as e:
# 删除临时文件
if os.path.exists(temp_path):
os.remove(temp_path)
return f"Error: {str(e)}"
# 创建Gradio界面
demo = gr.Interface(
fn=process_image,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Textbox(label="Model Name", value=DEFAULT_MODEL),
gr.Dropdown(choices=["transformers", "vllm"], value=DEFAULT_ENGINE, label="Inference Engine")
],
outputs=gr.Textbox(label="Result"),
title="Geolocation Reasoning App",
description="Upload an image, and the system will identify the country and region where the image was taken."
)
# 启动应用
if __name__ == "__main__":
demo.launch(share=True) |