| import gradio as gr | |
| import os | |
| def run_ollama(prompt): | |
| # 使用 Ollama 运行命令 | |
| try: | |
| response = os.popen(f"ollama run hf.co/{prompt}").read() | |
| return response.strip() # 确保返回值没有多余空格 | |
| except Exception as e: | |
| return f"Error: {str(e)}" # 捕获并返回错误信息 | |
| # 定义 Gradio 接口 | |
| iface = gr.Interface(fn=run_ollama, inputs="text", outputs="text", title="Ollama Model Runner") | |
| # 启动应用程序 | |
| if __name__ == "__main__": | |
| iface.launch() | |